Я создал образец плагина. Я хочу проверить это с включением Pytester. Do c ссылка: https://docs.pytest.org/en/latest/writing_plugins.html#testing -plugins
Однако, похоже, что pytester не находит плагин, который нужно протестировать.
Пожалуйста, найдите file_setup Я сделал.
poc_plugin
|- pytest_myplugin
| |- plugin.py
|- setup.py
|- pytest.ini
|- tests
|- conftest.py
|- test_myplugin.py
Пожалуйста, найдите файлы, которые я создал
setup.py
from setuptools import setup, find_packages
setup(
name="pytest-myplugin",
include_package_data=True,
python_requires=">=3.0, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
install_requires=[
"pytest>=5.3.5",
],
setup_requires=["pytest-runner"],
classifiers=[
"Framework :: Pytest",
],
packages=find_packages(include=["pytest_myplugin", "pytest_myplugin.*"]),
test_suite="tests",
entry_points={"pytest11": ["myplugin = pytest_myplugin.plugin"]},
version="0.1.0",
)
pytest_myplugin / plugin.py
import pytest
def pytest_addoption(parser):
"""
This is a pytest hook to add options from the command line.
"""
group = parser.getgroup("pytest-jay")
group.addoption(
"--jay",
action="store",
dest="jay",
default="package",
help="A Sample option",
)
conftest.py
pytest_plugins = ["pytester"]
tests / test_plugin.pt
import pytest
test_sample_txt = """
def test_sample():
assert True
"""
def test_pluging_one(testdir):
"""Make sure that pytest accepts our fixture."""
# create a temporary pytest test module
testdir.makepyfile(test_sample_txt)
# run pytest with the following cmd args
result = testdir.runpytest(
'--jay=jay',
)
# fnmatch_lines does an assertion internally
result.stdout.fnmatch_lines([
'*::test_sample PASSED*',
])
# make sure that that we get a '0' exit code for the testsuite
assert result.ret == 0
pytest.ini
[pytest]
testpaths = tests
Вывод, который я получаю ::
C:\Jay\Work\poc_plugin\tests\test_plugin.py:23: Failed
----------------------------------------------------------------------------------------- Captured stderr call ------------------------------------------------------------------------------------------
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --jay=jay
inifile: None
rootdir: C:\Users\jay.joshi\AppData\Local\Temp\pytest-of-jay.joshi\pytest-46\test_pluging_one0
======================================================================================== short test summary info ========================================================================================
FAILED tests/test_plugin.py::test_pluging_one - Failed: remains unmatched: '*::test_sample PASSED*'
=========================================================================================== 1 failed in 0.26s =====
Почему testdir не может найти плагин?