Debian Codegraph @

hypothesis-python/tests/pytest/test_pytest_detection.py

raw
1 # This file is part of Hypothesis, which may be found at
2 # https://github.com/HypothesisWorks/hypothesis/
3 #
4 # Copyright the Hypothesis Authors.
5 # Individual contributors are listed in AUTHORS.rst and the git log.
6 #
7 # This Source Code Form is subject to the terms of the Mozilla Public License,
8 # v. 2.0. If a copy of the MPL was not distributed with this file, You can
9 # obtain one at https://mozilla.org/MPL/2.0/.
10
11 import subprocess
12 import sys
13
14 from hypothesis import core
15
16
17 def test_is_running_under_pytest():
18 assert core.running_under_pytest
19
20
21 FILE_TO_RUN = """
22 import hypothesis.core as core
23 assert not core.running_under_pytest
24 """
25
26
27 def test_is_not_running_under_pytest(tmp_path):
28 pyfile = tmp_path / "test.py"
29 pyfile.write_text(FILE_TO_RUN, encoding="utf-8")
30 subprocess.check_call([sys.executable, str(pyfile)])
31
32
33 DOES_NOT_IMPORT_HYPOTHESIS = """
34 import sys
35
36 def test_pytest_plugin_does_not_import_hypothesis():
37 assert "hypothesis" not in sys.modules
38 """
39
40
41 def test_plugin_does_not_import_pytest(testdir):
42 testdir.makepyfile(DOES_NOT_IMPORT_HYPOTHESIS)
43 testdir.runpytest_subprocess().assert_outcomes(passed=1)