Skip to content

Commit

Permalink
fix: Prevent a TypeError when additional_checks is a list
Browse files Browse the repository at this point in the history
  • Loading branch information
Stranger6667 committed Jan 30, 2021
1 parent 7311d1f commit 079f645
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.rst
Expand Up @@ -8,6 +8,10 @@ Changelog

- Support for external examples via the ``externalValue`` keyword. `#884`_

**Fixed**

- Allow to use any iterable type for ``checks`` and ``additional_checks`` arguments to ``Case.validate_response``.

`3.0.4`_ - 2021-01-19
---------------------

Expand Down
4 changes: 2 additions & 2 deletions src/schemathesis/models.py
Expand Up @@ -5,6 +5,7 @@
from contextlib import contextmanager
from copy import deepcopy
from enum import IntEnum
from itertools import chain
from logging import LogRecord
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -355,9 +356,8 @@ def validate_response(
from .checks import ALL_CHECKS # pylint: disable=import-outside-toplevel

checks = checks or ALL_CHECKS
checks += additional_checks
errors = []
for check in checks:
for check in chain(checks, additional_checks):
try:
check(response, self)
except CheckFailed as exc:
Expand Down
3 changes: 3 additions & 0 deletions test/conftest.py
Expand Up @@ -520,6 +520,9 @@ def maker(
from test.utils import *
from hypothesis import given, settings, HealthCheck, Phase, assume, strategies as st
raw_schema = {schema}
note = print # An alias to distinguish with leftover prints
schema = schemathesis.from_dict(raw_schema, method={method}, endpoint={endpoint}, tag={tag}, validate_schema={validate_schema})
""".format(
schema=schema,
Expand Down
21 changes: 21 additions & 0 deletions test/test_pytest.py
Expand Up @@ -231,3 +231,24 @@ def test(case):
# Then this test should be skipped with a proper error message
result.assert_outcomes(skipped=1)
assert RECURSIVE_REFERENCE_ERROR_MESSAGE in result.stdout.str()


def test_checks_as_a_list(testdir, openapi3_base_url):
# When the user passes a list of checks instead of a tuple
testdir.make_test(
f"""
schema.base_url = "{openapi3_base_url}"
def my_check(response, case):
note("CHECKING!")
@schema.parametrize()
def test(case):
response = case.call()
case.validate_response(response, checks=(my_check,), additional_checks=[my_check])
""",
)
result = testdir.runpytest("-s")
# Then it should work
result.assert_outcomes(passed=1)
assert "CHECKING!" in result.stdout.str()

0 comments on commit 079f645

Please sign in to comment.