Testing

You should write tests as you write code – not as an afterthought once the project is complete.

Write tests

Test code tends to be written once and only read when the test fails. As a result, test code tends to be poorly written, with a lot of copy-pasting between test methods, which makes intent unclear.

To write clear tests:

Note

There are important caveats to using pytest with unittest.

Run tests

For Django applications:

python manage.py test

Otherwise, pytest is preferred. For applications:

pip-sync requirements_dev.txt
pytest

For packages:

pip install .[test]
pytest