Pytest: Class Method teardown() is Called by pytest, even though it is not documented

Created on 26 Mar 2020  路  3Comments  路  Source: pytest-dev/pytest

According to your documentation (https://docs.pytest.org/en/latest/xunit_setup.html), I can name a method teardown() in a test class, and it should not get run by pytest. I am using version pytest-3.8.2.

Pytest calls a method called teardown on class destruction even though it is specified as teardown_class in your documentation. I am guessing this accidentally did not get removed, when the names changed to teardown_class().

example:

import pytest


class TestExample:
    def teardown(self):
        print("SHOULD NOT GET RUN!!!!")

    def test_blah(self):
        print("Running example")

output:

 pytest -v -s bug_test.py 
=================================================================================================================================== test session starts ===================================================================================================================================
platform linux -- Python 3.6.9, pytest-3.8.2, py-1.7.0, pluggy-0.7.1 -- 
plugins: swte-2.0.0, mock-1.10.0
collected 1 item                                                                                                                                                                                                                                                                          

bug_test.py::TestExample::test_blah Running example
PASSEDSHOULD NOT GET RUN!!!!


====================================================================================================================================== REQUIREMENTS =======================================================================================================================================
================================================================================================================================ 1 passed in 0.03 seconds ===============
nose docs

Most helpful comment

would it be sensible to simply start to deprecate nose support, as far as i can tell the nose project is done

All 3 comments

I assume this is part of the general mapping of camelCase to snake_case conversion that pytest's unittest integration does... so it's probably treating it like https://docs.python.org/3/library/unittest.html#unittest.TestCase.tearDown

Hopefully someone who uses this plugin can tell us what's happening!

This is done by nose.py, probably to support the corresponding nose features. The documentation could be a bit clearer about it though, I'm guessing.

would it be sensible to simply start to deprecate nose support, as far as i can tell the nose project is done

Was this page helpful?
0 / 5 - 0 ratings