Skip to content

py.test ignores exceptions in fixtures #1480

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

Closed
Wilfred opened this issue Mar 24, 2016 · 10 comments
Closed

py.test ignores exceptions in fixtures #1480

Wilfred opened this issue Mar 24, 2016 · 10 comments
Labels
status: critical grave problem or usability issue that affects lots of users type: bug problem that needs to be addressed

Comments

@Wilfred
Copy link

Wilfred commented Mar 24, 2016

pytest seems to silently ignore any exception inside fixtures.

import pytest

@pytest.yield_fixture(scope='session', autouse=True)
def my_fixture():
    print "inside fixture"
    raise Exception("oh dear")
    yield

def test_foo():
    assert True

Running this with py.test exception.py -s gives:

exception.py inside fixture
.
================================================ 1 passed in 0.01 seconds =================================================

I would expect py.test to at least warn me that my fixture threw an error.

@RonnyPfannschmidt RonnyPfannschmidt added type: bug problem that needs to be addressed status: critical grave problem or usability issue that affects lots of users labels Mar 24, 2016
@nicoddemus
Copy link
Member

py.test does fail tests if a fixture raises an exception, as expected:

============================= test session starts =============================
platform win32 -- Python 2.7.11, pytest-2.9.2.dev1, py-1.4.31, pluggy-0.3.1
rootdir: X:\pytest, inifile: tox.ini
collected 1 items

foo.py inside fixture
E

=================================== ERRORS ====================================
_________________________ ERROR at setup of test_foo __________________________

    @pytest.yield_fixture(scope='session', autouse=True)
    def my_fixture():
        print("inside fixture")
>       raise Exception("oh dear")
E       Exception: oh dear

foo.py:6: Exception
=========================== 1 error in 0.06 seconds ===========================

(Tried this in both Python 2.7 and Python 3.5)

Which python and pytest versions are you using?

@Wilfred
Copy link
Author

Wilfred commented Mar 24, 2016

I'm using Python 2.7 with pytest 2.6.4.

@nicoddemus
Copy link
Member

2.6.4 is quite old... if this was a bug it was fixed already. 😁

@nicoddemus
Copy link
Member

(Please try upgrading pytest and reopen this if you still see the issue)

@Wilfred
Copy link
Author

Wilfred commented Mar 24, 2016

Worryingly, I'm seeing this on pytest 2.9.1 as well. I'll see if it's plugin related.

@RonnyPfannschmidt
Copy link
Member

please provide full output then, are you perhaps using pytest-sugar?

@nicoddemus nicoddemus reopened this Mar 24, 2016
@Wilfred
Copy link
Author

Wilfred commented Mar 24, 2016

Hmm, seems to be the "flaky" plugin. Uninstalling that makes the exception appear as expected.

$ py.test exception.py -s
===================================================================== test session starts =====================================================================
platform linux2 -- Python 2.7.3, pytest-2.9.1, py-1.4.31, pluggy-0.3.1
rootdir: redacted, inifile: setup.cfg
plugins: flaky-2.1.2
collected 1 items 

exception.py inside fixture
.
===Flaky Test Report===


===End Flaky Test Report===

================================================================== 1 passed in 0.01 seconds ===================================================================

@nicoddemus
Copy link
Member

OK, thanks for narrowing the problem down. Could you please post an issue on their tracker?

@Wilfred
Copy link
Author

Wilfred commented Mar 24, 2016

OK, seems to be fixed in flaky 3.1.1. Sorry for the noise.

@nicoddemus
Copy link
Member

No problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: critical grave problem or usability issue that affects lots of users type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

3 participants