Debian Codegraph @

hypothesis-python/tests/pytest/test_skipping.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 pytest_plugins = "pytester"
12
13
14 PYTEST_TESTSUITE = """
15 from hypothesis import given
16 from hypothesis.strategies import integers
17 import pytest
18
19 @given(xs=integers())
20 def test_to_be_skipped(xs):
21 # We always try the simplest example first, raising a Skipped exception
22 # which we know to propagate immediately...
23 if xs == 0:
24 pytest.skip()
25 # But the pytest 3.0 internals don't have such an exception, so we keep
26 # going and raise a BaseExceptionGroup error. Ah well.
27 else:
28 assert xs == 0
29 """
30
31
32 def test_no_falsifying_example_if_pytest_skip(testdir):
33 """If ``pytest.skip() is called during a test, Hypothesis should not
34 continue running the test and shrink process, nor should it print anything
35 about falsifying examples."""
36 script = testdir.makepyfile(PYTEST_TESTSUITE)
37 result = testdir.runpytest(
38 script, "--verbose", "--strict-markers", "-m", "hypothesis"
39 )
40 out = "\n".join(result.stdout.lines)
41 assert "Falsifying example" not in out
42
43
44 def test_issue_3453_regression(testdir):
45 """If ``pytest.skip() is called during a test, Hypothesis should not
46 continue running the test and shrink process, nor should it print anything
47 about falsifying examples."""
48 script = testdir.makepyfile(
49 """
50 from hypothesis import example, given, strategies as st
51 import pytest
52
53 @given(value=st.none())
54 @example("hello")
55 @example("goodbye")
56 def test_skip_on_first_skipping_example(value):
57 assert value is not None
58 assert value != "hello" # queue up a non-skip error which must be discarded
59 pytest.skip()
60 """
61 )
62 result = testdir.runpytest(script, "--tb=native")
63 result.assert_outcomes(skipped=1)