Check as a context manager: AttributeError: __enter__
I try to use the check as a context manager and get the error. Python verion: 3.10.5 Pytest version: 7.1.2 pytest-check version: 1.0.9
def test_multiple_failures():
with check: assert 1 == 0
with check: assert 1 > 2
with check: assert 1 < 5 < 4
tests/hdz_app/test_sample.py:9 (test_multiple_failures)
def test_multiple_failures():
> with check: assert 1 == 0
E AttributeError: __enter__
test_sample.py:11: AttributeError
Yikes.
I'm able to reproduce the problem. I'll look into it. Hopefully soon.
Hmmm. just tried again and it seemed to work fine. This is on a mac. I'll try again on a PC.
test_problem.py:
from pytest_check import check
def test_multiple_failures():
with check: assert 1 == 0
with check: assert 1 > 2
with check: assert 1 < 5 < 4
output seems right:
(pytest-check) $ pytest tests/test_problem.py
=============================== test session starts ================================
platform darwin -- Python 3.10.7, pytest-7.1.3, pluggy-1.0.0
rootdir: /Users/okken/projects/pytest-check, configfile: tox.ini
plugins: check-1.0.9
collected 1 item
tests/test_problem.py F [100%]
===================================== FAILURES =====================================
______________________________ test_multiple_failures ______________________________
FAILURE: assert 1 == 0
tests/test_problem.py:4 in test_multiple_failures() -> with check: assert 1 == 0
FAILURE: assert 1 > 2
tests/test_problem.py:5 in test_multiple_failures() -> with check: assert 1 > 2
FAILURE: assert 5 < 4
tests/test_problem.py:6 in test_multiple_failures() -> with check: assert 1 < 5 < 4
------------------------------------------------------------
Failed Checks: 3
============================= short test summary info ==============================
FAILED tests/test_problem.py::test_multiple_failures
================================ 1 failed in 0.02s =================================
Is this still a problem for you?
Can't recreate on windows either. Closing issue
@okken I met the same problem. I tried to migrate from pytest-assume to check
macOs python 3.8.13 pytest 7.1.2 pytest-check==1.0.10
import pytest_check as check
def test_smth():
with check: assert 2 < 1
with check: assert 3 < 2
test_smth.py:3 (test_smth)
def test_smth():
> with check: assert 2 < 1
E AttributeError: __enter__
test_smth.py:5: AttributeError
@ant1kdream I believe the import statement is incorrect.
Try changing: import pytest_check as check
to: from pytest_check import check
That should fix the problem you are seeing.
The documentation is perhaps the culprit of the confusion.
The documentation is perhaps the culprit of the confusion.
Thx! Yes, it is. I took import from first example in docs