@@ -79,53 +79,12 @@ How can I use ``manage.py test`` with pytest-django?
7979----------------------------------------------------
8080
8181pytest-django is designed to work with the ``pytest `` command, but if you
82- really need integration with ``manage.py test ``, you can create a simple
83- test runner like this :
82+ really need integration with ``manage.py test ``, you can add this class path
83+ in your Django settings :
8484
8585.. code-block :: python
8686
87- class PytestTestRunner :
88- """ Runs pytest to discover and run tests."""
89-
90- def __init__ (self , verbosity = 1 , failfast = False , keepdb = False , ** kwargs ):
91- self .verbosity = verbosity
92- self .failfast = failfast
93- self .keepdb = keepdb
94-
95- @ classmethod
96- def add_arguments (cls , parser ):
97- parser.add_argument(
98- ' --keepdb' , action = ' store_true' ,
99- help = ' Preserves the test DB between runs.'
100- )
101-
102- def run_tests (self , test_labels , ** kwargs ):
103- """ Run pytest and return the exitcode.
104-
105- It translates some of Django's test command option to pytest's.
106- """
107- import pytest
108-
109- argv = []
110- if self .verbosity == 0 :
111- argv.append(' --quiet' )
112- if self .verbosity == 2 :
113- argv.append(' --verbose' )
114- if self .verbosity == 3 :
115- argv.append(' -vv' )
116- if self .failfast:
117- argv.append(' --exitfirst' )
118- if self .keepdb:
119- argv.append(' --reuse-db' )
120-
121- argv.extend(test_labels)
122- return pytest.main(argv)
123-
124- Add the path to this class in your Django settings:
125-
126- .. code-block :: python
127-
128- TEST_RUNNER = ' my_project.runner.PytestTestRunner'
87+ TEST_RUNNER = ' pytest_django.runner.TestRunner'
12988
13089 Usage:
13190
0 commit comments