Skip to content
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

teardown method called even for skipped tests (and setup isn't) #265

Closed
pytestbot opened this issue Feb 13, 2013 · 2 comments
Closed

teardown method called even for skipped tests (and setup isn't) #265

pytestbot opened this issue Feb 13, 2013 · 2 comments
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Torsten Landschoff (BitBucket: bluehorn, GitHub: bluehorn)


I tried to skip all tests in a class when the specialized implementation is not available:

#!python

import pytest

class TestGeneric(object):
    def test_nothing(self):
        """Tests the API of the implementation (for generic and specialized)."""

@pytest.mark.skipif("True", reason="Skip tests to check if teardown is skipped as well.")
class TestSkipTeardown(TestGeneric):

    def setup(self):
        """Sets up my specialized implementation for $COOL_PLATFORM."""
        raise Exception("should not call setup for skipped tests")

    def teardown(self):
        """Undoes the setup."""
        raise Exception("should not call teardown for skipped tests")

The output is quite interesting:

#!python

(loco2-precise)torsten@sharokan:~/pytesttest$ py.test -rs -v
==================================================================================== test session starts ====================================================================================
platform linux2 -- Python 2.7.3 -- pytest-2.3.2 -- /opt/dynasdk/loco2-precise/bin/python
plugins: cov, capturelog, xdist
collected 2 items 

test_skip_teardown.py:4: TestGeneric.test_nothing PASSED
test_skip_teardown.py:4: TestSkipTeardown.test_nothing SKIPPED
test_skip_teardown.py:4: TestSkipTeardown.test_nothing ERROR

========================================================================================== ERRORS ===========================================================================================
____________________________________________________________________ ERROR at teardown of TestSkipTeardown.test_nothing _____________________________________________________________________

self = <test_skip_teardown.TestSkipTeardown object at 0x1ab9650>

    def teardown(self):
        """Undoes the setup."""
>       raise Exception("should not call teardown for skipped tests")
E       Exception: should not call teardown for skipped tests

test_skip_teardown.py:16: Exception
================================================================================== short test summary info ==================================================================================
SKIP [1] /opt/dynasdk/loco2-precise/lib/python2.7/site-packages/_pytest/skipping.py:120: Skip tests to check if teardown is skipped as well.
======================================================================= 1 passed, 1 skipped, 1 error in 0.02 seconds ========================================================================

Note that the same tests is reported as skipped and error at the same time. I would have expected that neither setup nor teardown is called for this case. I could understand that setup and teardown is called for each test and the test is skipped inside, but the current behaviour does not make sense IMHO.

My workaround was to use setup_method and teardown_method (ignoring the method parameter).

Greetings, Torsten


@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


bug confirmed also in recent pytest

@pytestbot
Copy link
Contributor Author

Original comment by Ronny Pfannschmidt (BitBucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt):


fix Issue 265 - integrate nose setup/teardown with setupstate

as sideeffect teardown is only called if setup doesnt fail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

1 participant