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

Allow check.check as a context manager when using check fixture #97

Merged
merged 2 commits into from
Nov 22, 2022
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
9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ All notable changes to this project be documented in this file.

- nothing so far
-->
## [1.1.3] - 2022-Nov-22

### Fixed

- While using the `check` fixture, allow `check.check` as a context manager.
- this is unnecessary, the `check` fixture now works as a context manager.
- but apparently some people have been using `with check.check:`
- so this fix makes that work.

## [1.1.2] - 2022-Nov-21

### Added
Expand Down
17 changes: 17 additions & 0 deletions examples/test_example_check_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
"with check.check:" - bad
"with check:" - good

However, we want both to work.
"""


def test_check(check):
with check:
assert True


def test_check_check(check):
"Deprecated, but should still work for now"
with check.check:
assert True
11 changes: 8 additions & 3 deletions src/pytest_check/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""A pytest plugin that allows multiple failures per test."""
__version__ = "1.1.2"
__version__ = "1.1.3"

import pytest

Expand All @@ -22,11 +22,16 @@
# assert 0
from pytest_check.check_raises import raises # noqa: F401, F402, F403

# make sure assert rewriting happens
pytest.register_assert_rewrite("pytest_check.check")

# allow check level raises
setattr(check, "raises", raises)

# make sure assert rewriting happens
pytest.register_assert_rewrite("pytest_check.check")
# allow check.check as a context manager.
# weird, but some people are doing it.
# decprecate this eventually
setattr(check, "check", check)

# allow for helper functions to be part of check context
# manager and check fixture:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_check_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def test_check_check(pytester):
pytester.copy_example("examples/test_example_check_check.py")
result = pytester.runpytest()
result.assert_outcomes(failed=0, passed=2)