From 7b3e0461e820f388f2c1fa0fca726284cbeb01bc Mon Sep 17 00:00:00 2001 From: Brian Okken <1568356+okken@users.noreply.github.com> Date: Tue, 22 Nov 2022 10:04:29 -0800 Subject: [PATCH 1/2] allow 'check.check' --- changelog.md | 9 +++++++++ examples/test_example_check_check.py | 16 ++++++++++++++++ src/pytest_check/__init__.py | 11 ++++++++--- tests/test_check_check.py | 4 ++++ 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 examples/test_example_check_check.py create mode 100644 tests/test_check_check.py diff --git a/changelog.md b/changelog.md index 5e2cd20..6d75305 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/examples/test_example_check_check.py b/examples/test_example_check_check.py new file mode 100644 index 0000000..6b38811 --- /dev/null +++ b/examples/test_example_check_check.py @@ -0,0 +1,16 @@ +""" +"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 + diff --git a/src/pytest_check/__init__.py b/src/pytest_check/__init__.py index d9a935a..3eb9374 100644 --- a/src/pytest_check/__init__.py +++ b/src/pytest_check/__init__.py @@ -1,5 +1,5 @@ """A pytest plugin that allows multiple failures per test.""" -__version__ = "1.1.2" +__version__ = "1.1.3" import pytest @@ -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: diff --git a/tests/test_check_check.py b/tests/test_check_check.py new file mode 100644 index 0000000..41c8286 --- /dev/null +++ b/tests/test_check_check.py @@ -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) From 08ccb7c7a374329d90dc81c876fef37e9aeafe6a Mon Sep 17 00:00:00 2001 From: Brian Okken <1568356+okken@users.noreply.github.com> Date: Tue, 22 Nov 2022 10:04:50 -0800 Subject: [PATCH 2/2] formatting --- examples/test_example_check_check.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/test_example_check_check.py b/examples/test_example_check_check.py index 6b38811..c4177d5 100644 --- a/examples/test_example_check_check.py +++ b/examples/test_example_check_check.py @@ -5,12 +5,13 @@ 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 -