Quick start to setup python script for Test Driven Development in 30 seconds
Time start!
Install Python virtual environment for human ( yay! ) pipenv
sudo pip install pipenv
create a directory and enter to it
mkdir my-tdd
cd my-tdd
Activate Python virtual environment, then the tool will automatically create it (if it’s not exist!)
pipenv shell
Install pytest as a dev dependency
pipenv install pytest --dev
create file and test file in any place of the directory
# in lib.py
def hello():
return "hello"
# in lib_test.py or test_lib.py
import lib
def test_hello():
assert lib.hello() == "hello"
let’s test
pytest
Getting result!
The structure will be like this
lib.py
lib_test.py
Pipfile
Pipfile.lock
You can use automatically test your code when the code's changed using pytest-watch
pipenv install pytest-watch
Let’s fun with TDD
ptw
Time stoppppppppppp!
As I said before, this blog will end within 30 seconds
Thanks guy, any question, pls comment
Good bye, see you
P.S. fastest blogging ever 🙏
Cross published at Medium.com