Skip to content

Commit

Permalink
Make tests more strict to address issues found by mutmut
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Dygalo authored and Stranger6667 committed Sep 30, 2019
1 parent 87a51ef commit 0ae63a1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
6 changes: 3 additions & 3 deletions test/test_common_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_(request, case):
result = testdir.runpytest("-v", "-s")
# Then this parameter should be used for all specified methods
result.assert_outcomes(passed=2)
result.stdout.re_match_lines([r"Hypothesis calls: 2"])
result.stdout.re_match_lines([r"Hypothesis calls: 2$"])


def test_common_parameters_with_references(testdir):
Expand Down Expand Up @@ -65,7 +65,7 @@ def test_b(request, case):
result = testdir.runpytest("-v", "-s")
# Then this parameter should be used in all generated tests
result.assert_outcomes(passed=4)
result.stdout.re_match_lines([r"Hypothesis calls: 4"])
result.stdout.re_match_lines([r"Hypothesis calls: 4$"])


def test_common_parameters_multiple_tests(testdir):
Expand Down Expand Up @@ -94,5 +94,5 @@ def test_b(request, case):
result = testdir.runpytest("-v", "-s")
# Then this parameter should be used in all test functions
result.assert_outcomes(passed=4)
result.stdout.re_match_lines([r"Hypothesis calls: 4"])
result.stdout.re_match_lines([r"Hypothesis calls: 4$"])
# NOTE: current implementation requires a deepcopy of the whole schema
16 changes: 8 additions & 8 deletions test/test_dereferencing.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_(request, case):
# Then it should be correctly resolved and used in the generated case
result = testdir.runpytest("-v", "-s")
result.assert_outcomes(passed=1)
result.stdout.re_match_lines([r"Hypothesis calls: 1"])
result.stdout.re_match_lines([r"Hypothesis calls: 1$"])


def test_recursive_dereference(testdir):
Expand Down Expand Up @@ -108,7 +108,7 @@ def test_(request, case):
# Then it should be correctly resolved and used in the generated case
result = testdir.runpytest("-v", "-s")
result.assert_outcomes(passed=1)
result.stdout.re_match_lines([r"Hypothesis calls: 1"])
result.stdout.re_match_lines([r"Hypothesis calls: 1$"])


def test_inner_dereference(testdir):
Expand Down Expand Up @@ -140,7 +140,7 @@ def test_(request, case):
# Then it should be correctly resolved and used in the generated case
result = testdir.runpytest("-v", "-s")
result.assert_outcomes(passed=1)
result.stdout.re_match_lines([r"Hypothesis calls: 1"])
result.stdout.re_match_lines([r"Hypothesis calls: 1$"])


def test_inner_dereference_with_lists(testdir):
Expand Down Expand Up @@ -176,7 +176,7 @@ def test_(request, case):
# Then it should be correctly resolved and used in the generated case
result = testdir.runpytest("-v", "-s")
result.assert_outcomes(passed=1)
result.stdout.re_match_lines([r"Hypothesis calls: 1"])
result.stdout.re_match_lines([r"Hypothesis calls: 1$"])


@pytest.mark.parametrize(
Expand Down Expand Up @@ -250,7 +250,7 @@ def test_(request, case):
# Then it should be correctly resolved and used in the generated case
result = testdir.runpytest("-v", "-s")
result.assert_outcomes(passed=1)
result.stdout.re_match_lines([r"Hypothesis calls: 1"])
result.stdout.re_match_lines([r"Hypothesis calls: 1$"])


def test_nullable_properties(testdir):
Expand All @@ -277,7 +277,7 @@ def test_(request, case):
# Then it should be correctly resolved and used in the generated case
result = testdir.runpytest("-vv", "-s")
result.assert_outcomes(passed=1)
result.stdout.re_match_lines([r"Hypothesis calls: 1"])
result.stdout.re_match_lines([r"Hypothesis calls: 1$"])


def test_nullable_ref(testdir):
Expand All @@ -297,7 +297,7 @@ def test_(request, case):
# Then it should be correctly resolved and used in the generated case
result = testdir.runpytest("-v", "-s")
result.assert_outcomes(passed=1)
result.stdout.re_match_lines([r"Hypothesis calls: 1"])
result.stdout.re_match_lines([r"Hypothesis calls: 1$"])


def test_nullable_enum(testdir):
Expand All @@ -316,4 +316,4 @@ def test_(request, case):
# Then it should be correctly resolved and used in the generated case
result = testdir.runpytest("-v", "-s")
result.assert_outcomes(passed=1)
result.stdout.re_match_lines([r"Hypothesis calls: 1"])
result.stdout.re_match_lines([r"Hypothesis calls: 1$"])
11 changes: 8 additions & 3 deletions test/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,29 @@ def test_loader_filter(testdir):
testdir.make_test(
"""
@schema.parametrize()
@settings(max_examples=1)
def test_(request, case):
request.config.HYPOTHESIS_CASES += 1
assert case.path == "/v1/foo"
assert case.method == "POST"
""",
paths={"/foo": {"post": {"parameters": [integer(name="id", required=True)]}}},
paths={
"/foo": {"post": {"parameters": []}, "get": {"parameters": []}},
"/bar": {"post": {"parameters": []}, "get": {"parameters": []}},
},
method="POST",
endpoint="/v1/foo",
)
result = testdir.runpytest("-v", "-s")
result.assert_outcomes(passed=1)
result.stdout.re_match_lines([r"Hypothesis calls: 1"])
result.stdout.re_match_lines([r"Hypothesis calls: 1$"])


def test_override_filter(testdir):
testdir.make_test(
"""
@schema.parametrize(method=None, endpoint="/v1/users")
@settings(max_examples=1)
def test_(request, case):
request.config.HYPOTHESIS_CASES += 1
assert case.path == "/v1/users"
Expand All @@ -84,4 +89,4 @@ def test_(request, case):
)
result = testdir.runpytest("-v", "-s")
result.assert_outcomes(passed=1)
result.stdout.re_match_lines([r"Hypothesis calls: 1"])
result.stdout.re_match_lines([r"Hypothesis calls: 1$"])
6 changes: 3 additions & 3 deletions test/test_lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_(request, case):
# Then settings should be applied to the test
result.assert_outcomes(passed=1)
result.stdout.re_match_lines([r"test_with_settings.py::test_ PASSED", r".*1 passed"])
result.stdout.re_match_lines([r"Hypothesis calls: 0"])
result.stdout.re_match_lines([r"Hypothesis calls: 0$"])


def test_with_fixtures(testdir):
Expand Down Expand Up @@ -70,7 +70,7 @@ def test_(request, case, another):
# Then the generated test should use these fixtures
result.assert_outcomes(passed=1)
result.stdout.re_match_lines([r"test_with_fixtures.py::test_ PASSED", r".*1 passed"])
result.stdout.re_match_lines([r"Hypothesis calls: 1"])
result.stdout.re_match_lines([r"Hypothesis calls: 1$"])


def test_with_filters(testdir):
Expand Down Expand Up @@ -103,7 +103,7 @@ def test_b(request, case):
result.stdout.re_match_lines(
[r"test_with_filters.py::test_a PASSED", r"test_with_filters.py::test_b PASSED", r".*2 passed"]
)
result.stdout.re_match_lines([r"Hypothesis calls: 2"])
result.stdout.re_match_lines([r"Hypothesis calls: 2$"])


def test_invalid_fixture(testdir):
Expand Down
6 changes: 3 additions & 3 deletions test/test_parametrization.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_(request, case):
result = testdir.runpytest("-v", "-s")
result.assert_outcomes(passed=2)
# Then total number of Hypothesis calls should be `max_examples` per pytest test
result.stdout.re_match_lines([r"Hypothesis calls: 10"])
result.stdout.re_match_lines([r"Hypothesis calls: 10$"])


def test_direct_schema(testdir):
Expand Down Expand Up @@ -93,7 +93,7 @@ def test_(request, case):
# Then it should be correctly used in the generated case
result = testdir.runpytest("-v", "-s")
result.assert_outcomes(passed=1)
result.stdout.re_match_lines([r"Hypothesis calls: 1"])
result.stdout.re_match_lines([r"Hypothesis calls: 1$"])


def test_specified_example(testdir):
Expand Down Expand Up @@ -122,7 +122,7 @@ def test(request, case):
result = testdir.runpytest("-v", "-s")
# Then this example should be used in tests
result.assert_outcomes(passed=1)
result.stdout.re_match_lines([r"Hypothesis calls: 1"])
result.stdout.re_match_lines([r"Hypothesis calls: 1$"])


def test_deselecting(testdir):
Expand Down
6 changes: 3 additions & 3 deletions test/test_required.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_(request, case):
)
result = testdir.runpytest("-v", "-s")
result.assert_outcomes(passed=1)
result.stdout.re_match_lines([r"Hypothesis calls: 20"])
result.stdout.re_match_lines([r"Hypothesis calls: 20$"])


def test_not_required_parameters(testdir):
Expand All @@ -40,7 +40,7 @@ def test_(request, case):
)
result = testdir.runpytest("-v", "-s")
result.assert_outcomes(passed=1)
result.stdout.re_match_lines([r"Hypothesis calls: 1"])
result.stdout.re_match_lines([r"Hypothesis calls: 1$"])


def test_without_required(testdir):
Expand All @@ -61,4 +61,4 @@ def test_(request, case):
# NOTE. could be flaky
result = testdir.runpytest("-v", "-s")
result.assert_outcomes(passed=1)
result.stdout.re_match_lines([r"Hypothesis calls: 1"])
result.stdout.re_match_lines([r"Hypothesis calls: 1$"])

0 comments on commit 0ae63a1

Please sign in to comment.