由于“ rootdir”和“ pytest.ini”文件存在问题而未找到装置

时间:2019-12-20 05:31:50

标签: pytest fixtures

我有Python 3.8.0, pytest 5.3.2和下一个目录布局:

project1
└── test_cases
    └── sample
    |   └── pytest.ini
    |   └── test_sample.py
    └── conftest.py
    └── pytest.ini

conftest.py文件的内容:

import pytest

@pytest.fixture
def fixture_sample():
    print('FIXTURE SAMPLE')

test_sample.py文件的内容:

def test_sample(fixture_sample):
    pass

我在project1目录中。
运行命令py.test -vs --rootdir ./test_cases/sample

user@machine:~/projects/project1$ py.test -vs --rootdir ./test_cases/sample
rootdir: /home/user/projects/project1/test_cases/sample
collected 1 item
test_cases/sample/test_sample.py::test_sample FIXTURE SAMPLE
PASSED

好的。但是我在输出消息中看不到inifile:pytest.ini。
接下来,我运行命令py.test -vs ./test_cases/sample

user@machine:~/projects/project1$ py.test -vs ./test_cases/sample
rootdir: /home/user/projects/project1/test_cases/sample, inifile: pytest.ini
collected 1 item
test_cases/sample/test_sample.py::test_sample ERROR
file /home/user/projects/project1/test_cases/sample/test_sample.py, line 1
  def test_sample(fixture_sample):
E       fixture 'fixture_sample' not found

有错误。在这两种情况下,我在输出消息和rootdir中看到inifile:pytest.ini相同。为什么不起作用?为什么找不到装置“ fixture_sample”?

0 个答案:

没有答案