Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port test runner to pytest #154

Merged
merged 3 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Version Next

* ...
* Port test runner to pytest.
* Fix compatibility issue with Werkezeug 3 related to deprecated ``request.charset``.

Version 0.39

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ lint: env/.done

.PHONY: test
test: env/.done
env/bin/python setup.py test
env/bin/pytest

.PHONY: tox
tox: env/bin/tox
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Development

To run a single test module invoke::

python setup.py test --test-suite acceptable.tests.test_module
env/bin/pytest acceptable/tests/test_module.py

or::

Expand Down
3 changes: 2 additions & 1 deletion acceptable/_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def wrapper(*args, **kwargs):
# is not informative enough.
if payload is None:
try:
payload = json.loads(request.data.decode(request.charset))
charset = request.mimetype_params.get("charset", "utf-8")
payload = json.loads(request.data.decode(charset))
except ValueError as e:
raise DataValidationError(
["Error decoding JSON request body: %s" % str(e)]
Expand Down
2 changes: 1 addition & 1 deletion acceptable/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _to_dict(source: Any):
return source._to_dict() # noqa
elif isinstance(source, dict):
return {key: _to_dict(value) for key, value in source.items()}
elif type(source) == list:
elif type(source) is list:
return [_to_dict(value) for value in source]
elif hasattr(source, "__dict__"):
return {key: _to_dict(value) for key, value in source.__dict__.items()}
Expand Down
3 changes: 2 additions & 1 deletion acceptable/tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ def match(self, response):
return mismatch
data = response.data
if self._decode:
data = data.decode(response.charset)
charset = response.mimetype_params.get("charset", "utf-8")
data = data.decode(charset)
return self.expected_content.match(data)

def __str__(self):
Expand Down
3 changes: 2 additions & 1 deletion acceptable/tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ def view():
self.assertRaises(AssertionError, app.post_json, [])

def assertResponseJsonEqual(self, response, expected_json):
data = json.loads(response.data.decode(response.charset))
charset = response.mimetype_params.get("charset", "utf-8")
data = json.loads(response.data.decode(charset))
self.assertEqual(expected_json, data)

def test_passes_on_good_payload_single_return_parameter(self):
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ skip-magic-trailing-comma = true
[tool.isort]
profile = "black"
skip = ["env", ".tox"]

[tool.pytest.ini_options]
addopts = "--cov=acceptable"

[tool.coverage.report]
omit = ["acceptable/tests/*"]
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ coveralls
flake8
fixtures
isort
pytest
pytest-cov
testscenarios
testtools
responses
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extras =
flask
django
commands =
coverage run --source acceptable --omit "acceptable/tests/*" setup.py test {posargs}
pytest {posargs}
passenv =
TRAVIS
TRAVIS_BRANCH
Expand Down
Loading