如果我使用命令“ pytest -s -v”运行测试用例 我的测试用例将获得pytest.ini文件所在的根目录路径。
但是我想在python测试会话开始之前以编程方式在“ conftest.py”文件中或从“ api”文件夹中的文件中找到根目录。 请注意:我想在pytest测试会话开始之前获取根目录
我在互联网上做了很多搜索,但没有得到我的要求的答案。 请帮助
我具有如下所示的python自动化项目结构。
api-automation
api
packagename
__init__.py
user.py
payloads
a.json
b.json
tests
test_1.py
test_2.py
conftest.py
setup.cfg
setup.py
pytest.ini
README.rst
conftest.py的内容如下
import pytest
@pytest.fixture(scope='session', autouse=True)
def root_directory(request):
"""
:return:
"""
return str(request.config.rootdir)
test_1.py的内容如下,
def test_first(root_directory):
print("root_directory", root_directory)