File tree Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Original file line number Diff line number Diff line change @@ -302,34 +302,31 @@ running from a test you can do something like this:
302
302
303
303
.. code-block :: python
304
304
305
- # content of conftest .py
305
+ # content of your_module .py
306
306
307
307
308
- def pytest_configure (config ):
309
- import sys
308
+ _called_from_test = False
310
309
311
- sys._called_from_test = True
310
+ .. code-block :: python
312
311
312
+ # content of conftest.py
313
313
314
- def pytest_unconfigure (config ):
315
- import sys
316
314
317
- del sys._called_from_test
315
+ def pytest_configure (config ):
316
+ your_module._called_from_test = True
318
317
319
- and then check for the ``sys ._called_from_test `` flag:
318
+ and then check for the ``your_module ._called_from_test `` flag:
320
319
321
320
.. code-block :: python
322
321
323
- if hasattr (sys, " _called_from_test" ) :
322
+ if your_module. _called_from_test:
324
323
# called from within a test run
325
324
...
326
325
else :
327
326
# called "normally"
328
327
...
329
328
330
- accordingly in your application. It's also a good idea
331
- to use your own application module rather than ``sys ``
332
- for handling flag.
329
+ accordingly in your application.
333
330
334
331
Adding info to test report header
335
332
--------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments