Anyway to disable --noconftest? #14715
Replies: 4 comments 1 reply
This comment was marked as disruptive content.
This comment was marked as disruptive content.
|
the flag was initially added 11 years ago to let linter plugins not fall apart in certain usages - its safe to assume it as unused in normal testing |
This comment was marked as low quality.
This comment was marked as low quality.
|
wouldn't try to make conftest.py itself enforce this, because --noconftest exists specifically to skip conftest discovery. For an accidental-safety guard, I'd move the check into a small pytest plugin installed with the test environment and register it through the pytest11 entry point. Then run the environment check from pytest_configure or pytest_sessionstart. --noconftest won't prevent an installed plugin from loading, so it covers the case you're worried about without adding an autouse fixture to every module. Something along these lines: myproject_pytest_guard/plugin.pyimport pytest def pytest_sessionstart(session): and register it in pyproject.toml: [project.entry-points.pytest11] I still wouldn't treat this as a security boundary: a developer can intentionally disable plugins too. For mounts/production resources, the real protection should stay outside pytest (permissions, container isolation, credentials, CI policy, etc.). But as a defense against accidentally running the suite in the wrong environment, an installed plugin is a much better fit than conftest.py |
Uh oh!
There was an error while loading. Please reload this page.
Hi All
I'm trying to build in session fixtures into my conftest which provide a layer of safety to ensure that they cannot be run in the wrong environment. However I noticed that pytest come with an option
--noconftestwhich appears to mean a developer could bypass any of those safe guards by not loading the conftest.I'm trying to find if there is anyway to disable this flag for this project, but there doesn't appear to be an obvious way to do this.
Of course I can't put anything in the conftest itself, since its not loaded. The only option I've been able to work out, its to ensure that every module has an autouse session fixture which depends on the one in the conftest, which will cause them to all error out because they can't find the unloaded fixture name.
Is there a way to disable this, or best practices about this?
Thanks
All reactions