Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pytest has several benefits over unittest: - captures stdout/stderr, restoring the ability to get an overview of the test run progress. To further improve the test run overview, the runner verbosity was decreased. - shows detailed reports for failures and errors The invocation is also much easier. Before this change: ``` DJANGO_SETTINGS_MODULE=config.settings.test django-admin --no-input --keepdb --parallel ``` With pytest (and a pytest.ini configuration), invocation is simply: ``` pytest ``` For more on pytest, see https://pytest-django.readthedocs.io/en/latest/index.html#why-would-i-use-this-instead-of-django-s-manage-py-test-command The `--failfast` option was not ported. It’s viewed as a hindrance by most team members, having to run the CI multiple times to get a full test report. With the simplified invocation, the `make test-interactive` recipe was no longer useful and was dropped. Also, passing arguments to the test runner (such as `-k TestFilter`) is also eased compared to the previous make TARGET variable. With make: ``` make test TARGET="-k TestFilter" ``` With pytest: ``` pytest -k TestFilter ``` Pytests parallel test runner splits the execution at the individual test level, whereas Django runner (based on unittest) splits at the TestCase level. That caused an issue with ImportSiaeManagementCommandsTest, which setup a test directory that would be shared by pytest workers. Update the test suite to use a temporary directory, specific to the worker process. Finally, add pytest-xdist as a dependency to support running the test suite in parallel.
- Loading branch information
1 parent
2fb036e
commit 3260fbb
Showing
6 changed files
with
36 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[pytest] | ||
DJANGO_SETTINGS_MODULE = config.settings.test | ||
python_files = test*.py | ||
addopts = --reuse-db --verbose --capture=no | ||
addopts = --numprocesses=logical --reuse-db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters