Pytest.raises (AssertionError) fails with cython modules

Define the python_assert.py and cython_assert.pyx files the same, each containing a simple function that raises AssertionError:

def raise_assertionerror(): assert False 

I would expect both tests to succeed in pytest:

 import pytest import pyximport pyximport.install() from python_assert import raise_assertionerror as python_assert from cython_assert import raise_assertionerror as cython_assert def test_assertion(): with pytest.raises(AssertionError): python_assert() def test_cython_assertion(): with pytest.raises(AssertionError): cython_assert() 

However, the cython test fails:

 ===================================== FAILURES ====================================== _______________________________ test_cython_assertion _______________________________ def test_cython_assertion(): with pytest.raises(AssertionError): > cython_assert() test_pytest_assertion.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > assert False E AssertionError cython_assert.pyx:2: AssertionError ======================== 1 failed, 1 passed in 0.61 seconds ========================= 

This is apparently a problem with pytest, because the unittest equivalent succeeds:

 import unittest import pyximport pyximport.install() from python_assert import raise_assertionerror as python_assert from cython_assert import raise_assertionerror as cython_assert class MyTestCase(unittest.TestCase): def test_cython(self): self.assertRaises(AssertionError, cython_assert) def test_python(self): self.assertRaises(AssertionError, python_assert) if __name__ == "__main__": unittest.main() 

In addition, the pytest test succeeds if we call pytest.raises(Exception) instead of pytest.raises(AssertionError) .

Any idea what is wrong?

+4
source share
1 answer

This is recognized as a bug in pytest and resolved.

+4
source

All Articles