ini文件中文乱码 python_pytest.ini文件未正确设置值

尝试在pytest.ini文件动态归档。testpaths选项决定pytest将从哪个目录收集测试。我想让用户能够选择测试目录a或{}。在

conftest.py

第一个钩子创建一个解析器选项。

第二个钩子拉动解析器选项读取值,并将testpath添加到config对象下的testpaths选项中。在@pytest.hookimpl()

def pytest_addoption(parser):

“””Creates a parser option”””

Allows the user to select the test suite they want to run

parser.addoption(“–suite”, action=”store”, default=”None”

, choices=[‘a’, ‘b’]

, help=”Choose which test suite to run.”)

@pytest.hookimpl()

def pytest_configure(config):

print(“Determining test directory”)

suite = config.getoption(“–suite”)

if suite == “a”:

config.addinivalue_line(“testpaths”, “tests/a”)

elif suite == “b”:

config.addinivalue_line(“testpaths”, “tests/b”)

因此,如果我运行pytest –suite a,它应该加载a测试套件下的所有测试。它没有。它加载所有测试,就像选项不存在一样。在

Original: https://blog.csdn.net/weixin_31834275/article/details/113387024
Author: 哎呀吗呀咪呀
Title: ini文件中文乱码 python_pytest.ini文件未正确设置值

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/774403/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球