Python 在测试结束时获取pytest中所有请求的装置的列表

Python 在测试结束时获取pytest中所有请求的装置的列表,python,pytest,fixtures,Python,Pytest,Fixtures,我有以下示例代码: # In my conftest.py @pytest.mark.fixture(scope="function") def func_fix(): ... @pytest.mark.fixture(scope="session") def sess_fix(): ... def pytest_unconfigure(config): # HELP NEEDED # In my test code: def test_foo(sess_fix,

我有以下示例代码:

# In my conftest.py
@pytest.mark.fixture(scope="function")
def func_fix():
    ...

@pytest.mark.fixture(scope="session")
def sess_fix():
    ...

def pytest_unconfigure(config):
    # HELP NEEDED

# In my test code:
def test_foo(sess_fix, func_fix):
    ...
我想根据是否请求了
func\u fix()
在pytest\u unconfigure中执行操作。在另一个获取
request
的fixture中,我可以检查
request.fixturenames
,但我不确定如何在pytest\u unconfigure()中执行此操作。我目前的解决方案是在
func\u fix()
中设置
config.foo=bar
,然后在
pytest\u unconfigure()
中检查,假设一切正常

问题是当
sess\u fix()
失败时,
config.foo=bar
显然没有设置,因此我无法在
pytest\u unconfigure()中采取操作

我不需要运行
func\u fix()
。我只需要知道用户想要运行它

编辑:我承认我在这里滥用了终结器。我也欢迎任何关于更好地处理拆卸功能的建议


有什么方法可以做到这一点吗?

为什么不专门为
func\u fix
添加一个终结器/拆卸?为什么不专门为
func\u fix
添加一个终结器/拆卸?