py.test在同一目录结构中不能有相同选项名称的pytest_addoption

时间:2012-08-01 08:31:35

标签: optparse pytest

我有以下测试目录结构,每个都有自己的conftest.py:

    tests/api
    tests/api/newapi
    tests/sanity

在conftest.py中,pytest_addoption具有与test_option相同的选项:

parser.addoption(“ - test_option”,dest =“test_option”,type =“string”,help =“test_option”)

在tests / api / newapi执行py.test有以下错误:

optparse.OptionConflictError:option --test_option:冲突的选项字符串: - test_option

但是在tests / api上执行py.test或者测试或者测试/健全工作正常。 根据设计,如果父目录具有相同的选项名称,我必须提出新的选项名​​称吗?

我希望我能保持命名约定相同,因为有问题的选项对测试起着同样的作用。目的是根据测试从哪个目录开始改变测试的详细程度。

1 个答案:

答案 0 :(得分:1)

我认为你应该有一个test / conftest.py,它通过pytest_addoption定义选项,你可以从任何地方访问它,因为所有的conftest.py文件都被考虑了(所以你可能仍然在test / newapi / conftest .py并使用选项值)。