The Python "teardown_class" is not behaving as I expect it to. Below is a summary of my code:
@classmethod
def setup_class(cls):
cls.create_table(table1)
cls.create_table(table2)
cls.create_table(table3)
@classmethod
def create_table(cls, some_arg_here):
"""Some code here that creates the table"""
def test_foo(self):
"""Some test code here"""
@classmethod
def teardown_class(cls):
"""Perform teardown things"""
Python 2.7.10, pytest-3.6.2, py-1.5.3, pluggy-0.6.0
I was able to find the solution. I recreated the create_table
function as an inner function, inside of the setup
function.
@classmethod
def setup_class(cls):
def create_table(some_arg_here):
"""Some code here that creates the table"""
create_table(table1)
create_table(table2)
create_table(table3)
def test_foo(self):
"""Some test code here"""
@classmethod
def teardown_class(cls):
"""Perform teardown things"""
And now it runs as I expect it to, in this sequence:
create_table
once for table1 paramcreate_table
once for table2 paramcreate_table
once for table3 paramtest_foo
teardown_class
It seems that any/every time a function that is outside of setup
is called from setup
, it causes the teardown
function to run directly after the code in the outer function runs, and that was the issue I was facing.