We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c650e3a commit 43ce185Copy full SHA for 43ce185
doc/en/example/simple.rst
@@ -409,25 +409,13 @@ running from a test you can do something like this:
409
410
.. code-block:: python
411
412
- # content of your_module.py
413
-
414
415
- _called_from_test = False
416
417
-.. code-block:: python
418
419
- # content of conftest.py
420
421
422
- def pytest_configure(config):
423
- your_module._called_from_test = True
+ import sys
424
425
-and then check for the ``your_module._called_from_test`` flag:
426
427
+ _called_from_test_by_pytest = "pytest" in sys.modules
428
429
- if your_module._called_from_test:
430
- # called from within a test run
+ if _called_from_test_by_pytest:
+ # called from within a test run by pytest
431
...
432
else:
433
# called "normally"
0 commit comments