Skip to content

Commit

Permalink
Update advice about _called_from_test. (#6168)
Browse files Browse the repository at this point in the history
Update advice about _called_from_test.
  • Loading branch information
nicoddemus committed Nov 14, 2019
2 parents 92d6a05 + bd68c2a commit e2a0987
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions doc/en/example/simple.rst
Expand Up @@ -302,34 +302,31 @@ running from a test you can do something like this:

.. code-block:: python
# content of conftest.py
# content of your_module.py
def pytest_configure(config):
import sys
_called_from_test = False
sys._called_from_test = True
.. code-block:: python
# content of conftest.py
def pytest_unconfigure(config):
import sys
del sys._called_from_test
def pytest_configure(config):
your_module._called_from_test = True
and then check for the ``sys._called_from_test`` flag:
and then check for the ``your_module._called_from_test`` flag:

.. code-block:: python
if hasattr(sys, "_called_from_test"):
if your_module._called_from_test:
# called from within a test run
...
else:
# called "normally"
...
accordingly in your application. It's also a good idea
to use your own application module rather than ``sys``
for handling flag.
accordingly in your application.

Adding info to test report header
--------------------------------------------------------------
Expand Down

0 comments on commit e2a0987

Please sign in to comment.