我正在尝试做什么
我正在使用 pytest 在 python 中编写一个小型框架,作为拆解的一部分,我正在截取屏幕截图。 现在,我希望根据正在运行的测试来命名该屏幕截图,而不是 conftest.py 例如,我现在的代码是:
driver.save_screenshot(os.path.basename(__file__)+'.png')
问题
这会打印名称“conftest.py”。 如果可能的话,我想打印调用测试的名称。我猜使用请求?
最佳答案
您可以通过request.node.fspath
访问当前文件路径。示例:
# conftest.py
import pytest
@pytest.fixture
def currpath(request):
return str(request.node.fspath)
关于python - 从conftest.py访问测试文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50393354/