Managing Test Environments with tox
tox is a command-line tool used alongside pytest to automate test execution across multiple Python versions, dependency sets, or environments. In this setup, pytest acts as the test runner, while tox orchestrates how and where tests are executed.
An example tox.ini configuration might look like this:
[tox]
envlist = py39, py310
[testenv]
deps = pytest
commands = pytest
[pytest]
addopts = -rsxX -l --tb=short --strict
As shown above, the pytest.ini configuration is also moved into tox.ini when using tox.
Running tox will create isolated virtual environments, install pytest and dependencies and execute the test suite in each environment. This combination is especially powerful for libraries that need to support multiple Python versions or optional dependencies.
unittest
pytest is compatible with Python’s built-in unittest framework and can discover and run most unittest-based tests without modification. This makes pytest a practical choice for projects migrating gradually from unittest to pytest.
Jenkins CI
Jenkins is a popular automation tool used to run tasks such as building applications and executing tests whenever code changes. It is most commonly used for continuous integration (CI), a development practice where tests are run automatically each time new code is added to a shared repository. The goal of CI is to catch bugs early by verifying that new changes do not break existing functionality.
