Getting Started TDD in 30 Seconds with Python
--
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
2. create a directory and enter to it
mkdir my-tdd
cd my-tdd
3. Activate Python virtual environment, then the tool will automatically create it (if it’s not exist!)
pipenv shell
4. Install pytest as a dev dependency
pipenv install pytest --dev
5. create file and test file in any place of the directory
# in lib.pydef hello():
return "hello"# in lib_test.py or test_lib.pyimport lib
def test_hello():
assert lib.hello() == "hello"
6. let’s test
pytest
Getting result!
The structure will be like this
lib.py
lib_test.py
Pipfile
Pipfile.lock
Extra!
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 🙏
Originally published at mildronize.com.