Skip to content

Chapter 5: Building and maintaining a test suite

  • The book recommends using pytest over builtin python module unittest. It seems that the first has some advantages and helpful utilities. (pytest-cov, pytest-randomly...)
  • In order to use pytest in your project, you must install in the same virtual environment as your project.
  • Happy path tests: Easy, frequent and less error-prone test cases. In contrast with unhappy path tests.
  • Use @pytest.mark.paremetrize to speed-up the creation of data variation of your tests.
  • Use tox to test your code across all combinations (test matrix) of python versions and dependencies versions.
  • Use tox -e <AN ENVIRONMENT> during development in order to not run the tests in all test matrix.
  • Use tox -p to execute tox in parallel.
  • Use --randomly-seed=<SEED> option of pytest to reexecute the test in a specified order.
  • pytest architecture is modular. You can extend it by adding plugins to it. You can have, for example, another markers (decorators) available by installing the appropriated plugin.
  • use the placeholder {posargs} to pass parameters at invocation time. tox -e my_env -- everything_passed_here_substitutes_posargs