pytest-check icon indicating copy to clipboard operation
pytest-check copied to clipboard

Check as a context manager: AttributeError: __enter__

Open zerocen opened this issue 3 years ago • 2 comments

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

zerocen avatar Aug 29 '22 06:08 zerocen

Yikes.

okken avatar Sep 01 '22 19:09 okken

I'm able to reproduce the problem. I'll look into it. Hopefully soon.

okken avatar Sep 01 '22 19:09 okken

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 =================================

okken avatar Sep 26 '22 02:09 okken

Is this still a problem for you?

okken avatar Sep 26 '22 02:09 okken

Can't recreate on windows either. Closing issue

okken avatar Sep 29 '22 03:09 okken

@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 avatar Oct 05 '22 08:10 ant1kdream

@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.

okken avatar Oct 05 '22 16:10 okken

The documentation is perhaps the culprit of the confusion.

okken avatar Oct 05 '22 16:10 okken

The documentation is perhaps the culprit of the confusion.

Thx! Yes, it is. I took import from first example in docs

ant1kdream avatar Oct 06 '22 06:10 ant1kdream