Skip to content

Commit

Permalink
fix: Pytest 5.4 warning for test functions without parametrization (#466
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Stranger6667 committed Apr 3, 2020
1 parent 8aeee1a commit dd9042b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Expand Up @@ -12,6 +12,7 @@ Fixed
- Precedence of ``produces`` keywords for Swagger 2.0 schemas. Now, operation-level ``produces`` overrides
schema-level ``produces`` as specified in the specification. `#463`_
- Content Type conformance check for Open API 3.0 schemas. `#461`_
- Pytest 5.4 warning for test functions without parametrization. `#451`_

`1.0.2`_ - 2020-04-02
---------------------
Expand Down
10 changes: 5 additions & 5 deletions src/schemathesis/extra/pytest_plugin.py
Expand Up @@ -49,18 +49,18 @@ def _gen_items(self, endpoint: Endpoint) -> Generator[Function, None, None]:

metafunc = self._parametrize(cls, definition, fixtureinfo)

if USE_FROM_PARENT:
create_function = SchemathesisFunction.from_parent
else:
create_function = SchemathesisFunction
if not metafunc._calls:
yield SchemathesisFunction(name, parent=self.parent, callobj=funcobj, fixtureinfo=fixtureinfo)
yield create_function(name=name, parent=self.parent, callobj=funcobj, fixtureinfo=fixtureinfo)
else:
fixtures.add_funcarg_pseudo_fixture_def(self.parent, metafunc, fixturemanager)
fixtureinfo.prune_dependency_tree()

for callspec in metafunc._calls:
subname = "{}[{}]".format(name, callspec.id)
if USE_FROM_PARENT:
create_function = SchemathesisFunction.from_parent
else:
create_function = SchemathesisFunction
yield create_function(
name=subname,
parent=self.parent,
Expand Down
8 changes: 6 additions & 2 deletions test/test_pytest.py
Expand Up @@ -100,12 +100,16 @@ def test_pytest_warning(testdir):
testdir.make_test(
"""
@schema.parametrize()
def test_a(case):
assert True
@schema.parametrize()
@pytest.mark.parametrize("a", (1, 2))
def test_schemathesis(case, a):
def test_b(case, a):
assert True
""",
)
# When a test is run with treating warnings as errors
result = testdir.runpytest("-Werror")
# There should be no errors. There are no warnings from Schemathesis pytest plugin
result.assert_outcomes(passed=2)
result.assert_outcomes(passed=3)

0 comments on commit dd9042b

Please sign in to comment.