Python“teardown_class”的行为不像我预期的那样。以下是我的代码的摘要:
@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"""
我相信它的执行方式是:
- 正在使用第一个参数(table1)从设置中调用 create_table
- create_table 中的代码执行
- teardown_class 中的代码执行
- 上面的1-3用第二个参数再次执行
- 上面的1-3用第3个参数再次执行
- test_foo 中的代码执行
我期望它如何执行:
- 使用第一个参数 (table1) 调用 create_table
- create_table 中的代码执行
- 使用第二个参数调用 create_table(表 2)
- create_table 中的代码执行
- 使用第三个参数调用 create_table(表 3)
- create_table 中的代码执行
- test_foo 中的代码执行
- teardown_class 中的代码执行
Python 2.7.10、pytest-3.6.2、py-1.5.3、pluggy-0.6.0