Skip to content

Commit

Permalink
Add test for pytest test selecting. Closes #33
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Dygalo committed Sep 13, 2019
1 parent 78fde7e commit 233437c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/schemathesis/extra/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ def _gen_items(self, endpoint: Endpoint) -> Generator[Function, None, None]:
Could produce more than one test item if
parametrization is applied via ``pytest.mark.parametrize`` or ``pytest_generate_tests``.
"""
# TODO. exclude it early, if tests are deselected, then hypothesis strategies will not be used anyway
# But, it is important to know the total number of tests for all method/endpoint combos
hypothesis_item = create_hypothesis_test(endpoint, self.test_function)
items = self.ihook.pytest_pycollect_makeitem(
collector=self.parent, name=self._get_test_name(endpoint), obj=hypothesis_item
Expand Down
23 changes: 23 additions & 0 deletions test/schemas/test_parametrization.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,29 @@ def test(request, case):
result.stdout.re_match_lines([r"Hypothesis calls: 1"])


def test_deselecting(testdir):
# When pytest selecting is applied via "-k" option
testdir.make_test(
"""
@schema.parametrize()
@settings(max_examples=1)
def test_a(request, case):
request.config.HYPOTHESIS_CASES += 1
@schema.parametrize(filter_endpoint="pets")
@settings(max_examples=1)
def test_b(request, case):
request.config.HYPOTHESIS_CASES += 1
""",
paths={"/pets": {"post": {}}},
)
result = testdir.runpytest("-v", "-s", "-k", "pets")
# Then only relevant tests should be selected for running
result.assert_outcomes(passed=2)
# "/users" endpoint is excluded in the first test function
result.stdout.re_match_lines([".* 1 deselected / 2 selected", r".*\[POST:/v1/pets\]", r"Hypothesis calls: 2"])


def test_required_parameters(testdir):
testdir.make_test(
"""
Expand Down

0 comments on commit 233437c

Please sign in to comment.