Debian Codegraph @

hypothesis-python/tests/pytest/test__pytest.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 os
12 import subprocess
13 import sys
14
15 TESTSUITE = """
16 from hypothesis import given
17 from hypothesis import strategies as st
18 import _pytest
19
20 @given(st.integers())
21 def test_a(n):
22 pass
23
24 test_a()
25 """
26
27
28 def test_import_just_private_pytest_works(testdir):
29 # importing just _pytest does not import its submodules like _pytest.outcomes.
30 # Ensure we don't rely on this by writing conditional imports like
31 # `if "_pytest" in sys.modules: sys.modules["_pytest"].outcomes`.
32 script = testdir.makepyfile(TESTSUITE)
33 result = subprocess.run(
34 [sys.executable, script],
35 # some hypothesis plugins (trio) import pytest, making this test pass
36 # even when hypothesis has a bug. This was the case for my local installation,
37 # and I am including this here on the off chance our CI setup has a similar
38 # install situation. I don't want to wait for another regression to find out
39 # this test doesn't work.
40 env=os.environ | {"HYPOTHESIS_NO_PLUGINS": "1"},
41 )
42 assert result.returncode == 0