usage.rst 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. .. _usage:
  2. Usage and invocations
  3. =====================
  4. Basic usage
  5. -----------
  6. When using pytest-django, django-admin.py or manage.py is not used to run
  7. tests. This makes it possible to invoke pytest and other plugins with all its
  8. different options directly.
  9. Running a test suite is done by invoking the pytest command directly::
  10. pytest
  11. Specific test files or directories can be selected by specifying the test file names directly on
  12. the command line::
  13. pytest test_something.py a_directory
  14. See the `pytest documentation on Usage and invocations
  15. <https://pytest.org/en/latest/usage.html>`_ for more help on available parameters.
  16. Additional command line options
  17. -------------------------------
  18. ``--fail-on-template-vars`` - fail for invalid variables in templates
  19. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  20. Fail tests that render templates which make use of invalid template variables.
  21. Running tests in parallel with pytest-xdist
  22. -------------------------------------------
  23. pytest-django supports running tests on multiple processes to speed up test
  24. suite run time. This can lead to significant speed improvements on multi
  25. core/multi CPU machines.
  26. This requires the pytest-xdist plugin to be available, it can usually be
  27. installed with::
  28. pip install pytest-xdist
  29. You can then run the tests by running::
  30. pytest -n <number of processes>
  31. When tests are invoked with xdist, pytest-django will create a separate test
  32. database for each process. Each test database will be given a suffix
  33. (something like "gw0", "gw1") to map to a xdist process. If your database name
  34. is set to "foo", the test database with xdist will be "test_foo_gw0",
  35. "test_foo_gw1" etc.
  36. See the full documentation on `pytest-xdist
  37. <https://pytest.org/en/latest/xdist.html>`_ for more information. Among other
  38. features, pytest-xdist can distribute/coordinate test execution on remote
  39. machines.