Thanks background from vecteezy

Getting Started TDD in 30 Seconds with Python

Thada Wangthammang
Sep 8, 2018 · 2 min read

Quick start to setup python script for Test Driven Development in 30 seconds

Time start!

  1. 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.

Thada Wangthammang

Written by

A lecturer, a full stack developer. Currently, optimizing OpenTSDB query time using cache. Blog at mildronize.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade