| 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 |
from tests.common.utils import skipif_emscripten |
| 16 |
|
| 17 |
SHOULD_NOT_IMPORT_TEST_RUNNERS = """ |
| 18 |
import sys |
| 19 |
import unittest |
| 20 |
from hypothesis import given, strategies as st |
| 21 |
|
| 22 |
class TestDoesNotImportRunners(unittest.TestCase): |
| 23 |
strat = st.integers() | st.floats() | st.sampled_from(["a", "b"]) |
| 24 |
|
| 25 |
@given(strat) |
| 26 |
def test_does_not_import_unittest2(self, x): |
| 27 |
assert "unittest2" not in sys.modules |
| 28 |
|
| 29 |
@given(strat) |
| 30 |
def test_does_not_import_nose(self, x): |
| 31 |
assert "nose" not in sys.modules |
| 32 |
assert "nose2" not in sys.modules |
| 33 |
|
| 34 |
@given(strat) |
| 35 |
def test_does_not_import_pytest(self, x): |
| 36 |
assert "pytest" not in sys.modules |
| 37 |
|
| 38 |
if __name__ == '__main__': |
| 39 |
unittest.main() |
| 40 |
""" |
| 41 |
|
| 42 |
|
| 43 |
@skipif_emscripten |
| 44 |
def test_hypothesis_does_not_import_test_runners(tmp_path): |
| 45 |
# We obviously can't use pytest to check that pytest is not imported, |
| 46 |
# so for consistency we use unittest for all three non-stdlib test runners. |
| 47 |
# It's unclear which of our dependencies is importing unittest, but |
| 48 |
# since I doubt it's causing any spurious failures I don't really care. |
| 49 |
# See https://github.com/HypothesisWorks/hypothesis/pull/2204 |
| 50 |
fname = tmp_path / "test.py" |
| 51 |
fname.write_text(SHOULD_NOT_IMPORT_TEST_RUNNERS, encoding="utf-8") |
| 52 |
subprocess.check_call( |
| 53 |
[sys.executable, str(fname)], |
| 54 |
env={**os.environ, "HYPOTHESIS_NO_PLUGINS": "1"}, |
| 55 |
) |