-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[8.1.x][8.3.x] testpaths
not taken into account for initial conftests loading when set through configuration file?
#12696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
testpaths
not taken into account for initial conftests loading when set through configuration file?testpaths
not taken into account for initial conftests loading when set through configuration file?
I'm currently trying to take care of it and I've set up a dev environment but I'm not able to produce a test that could fail on this. There already is a test covering similar cases but in doubt I've tried the following that is very similar (if not duplicate) to But it passes. def test_initial_conftests_with_testpaths_bis(pytester: Pytester) -> None:
"""
Trying to reproduce #12696.
"""
# Create the pyproject.toml.
pytester.path.joinpath("pyproject.toml").write_text(
textwrap.dedent(
"""
[tool.pytest.ini_options]
testpaths = [
"my_project/my_tests",
]
"""
),
encoding="utf-8",
)
# Create the conftest.
pytester.mkdir("my_project")
p = pytester.mkdir("my_project/my_tests")
p.joinpath("conftest.py").write_text(
textwrap.dedent(
"""
def pytest_sessionstart(session):
raise Exception("pytest_sessionstart hook successfully run")
"""
),
encoding="utf-8",
)
result = pytester.runpytest()
assert result.ret == ExitCode.INTERNAL_ERROR
result.stdout.fnmatch_lines(
"INTERNALERROR* Exception: pytest_sessionstart hook successfully run"
)
# No fallback.
result = pytester.runpytest(".")
assert result.ret == ExitCode.NO_TESTS_COLLECTED So I'm looking for hints or alternate hypotheses to explain the behavior I observe. Erratum:I think I didn't go deep enough. |
I tried to make and run the following tests to reproduce the usage error but those tests pass. class TestAddoptionHookInNonRootConftest:
"""
Trying to reproduce #12696.
"""
def test_pytest_addoption_hook_with_command_line_testpaths(self, pytester: Pytester) -> None:
# Create the conftest.
pytester.mkdir("my_project")
p = pytester.mkdir("my_project/my_tests")
p.joinpath("conftest.py").write_text(
textwrap.dedent(
f"""
def pytest_addoption(parser):
parser.addoption("--XX", action="store_true")
"""
),
encoding="utf-8",
)
# No command line args - falls back to testpaths.
result = pytester.runpytest("my_project/my_tests", "--XX")
assert result.ret == ExitCode.NO_TESTS_COLLECTED
def test_pytest_addoption_hook_with_configured_testpaths(self, pytester: Pytester) -> None:
# Creating the pyproject.toml file.
pytester.path.joinpath("pyproject.toml").write_text(
textwrap.dedent(
"""
[tool.pytest.ini_options]
testpaths = [
"my_project/my_tests",
]
"""
),
encoding="utf-8",
)
# Create the conftest.
pytester.mkdir("my_project")
p = pytester.mkdir("my_project/my_tests")
p.joinpath("conftest.py").write_text(
textwrap.dedent(
f"""
def pytest_addoption(parser):
parser.addoption("--XX", action="store_true")
"""
),
encoding="utf-8",
)
# No command line args - should fall back to configured testpaths.
result = pytester.runpytest("--XX")
assert result.ret == ExitCode.NO_TESTS_COLLECTED Perhaps it's not a bug finally and rather something I messed up. Perhaps I should fill a support request instead? |
Oh. * Facepalm * I just found out I was indeed a usage error.
My bad and sorry for the inconvenience! |
Related: #8846 |
I'm trying to set up a custom command line option with the
pytest_addoption
hook in a non-rootconftest.py
file but it looks like that somehow my conftest isn't taken into account as an initial one if thetestpaths
is set through a configuration file (pyproject.toml
in my example but it was also reproduced with apytest.ini
).However, things work if the
testpaths
is explicitly set by command line argument.Versions used are:
The OS is a Linux environment:
I made a SO post on this issue yesterday and someone pointed out a similar issue (#10988). Could it be a regression?
MRE :
Command
pytest --foo bar
run in a directory containing the files:./my_project/my_tests/conftest.py
:./my_project/my_tests/test_foo.py
:./my_project/my_tests/__init__.py
file.Expected behaviour:
An output similar to the one a simple workaround (giving the testpath explicitly by command line) gives:
Observed behaviour:
I get the following usage error:
The text was updated successfully, but these errors were encountered: