对于包或目录级别的fixture,您可以使用 scope='session' 在您需要的目录中的 conftest.py 文件中声明一个fixture . 一旦包/目录中的第一个测试使用它,就会实例化fixture . 这是an example但是,如果fixture函数注册了终结器,您可能会看到它在该目录中的最后一次测试之后没有直接执行 . 我认为pytest可以支持更急切的拆解或者在需要时引入"directory"范围 . 通常它's not a big problem if the teardown executes a little later as long as it doesn' t执行得太早了:)注意显然杰森intends to drop package-level setup/teardown support for nose
1 回答
对于包或目录级别的fixture,您可以使用
scope='session'
在您需要的目录中的conftest.py
文件中声明一个fixture . 一旦包/目录中的第一个测试使用它,就会实例化fixture . 这是an example但是,如果fixture函数注册了终结器,您可能会看到它在该目录中的最后一次测试之后没有直接执行 . 我认为pytest可以支持更急切的拆解或者在需要时引入"directory"范围 . 通常它's not a big problem if the teardown executes a little later as long as it doesn' t执行得太早了:)注意显然杰森intends to drop package-level setup/teardown support for nose无论如何,如果您需要更热切/精确的pytest拆解,请随时open an issue .