@@ -79,53 +79,12 @@ How can I use ``manage.py test`` with pytest-django?
79
79
----------------------------------------------------
80
80
81
81
pytest-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 :
84
84
85
85
.. code-block :: python
86
86
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'
129
88
130
89
Usage:
131
90
0 commit comments