Fix --help/--version when conftest imports models#1275
Fix --help/--version when conftest imports models#1275brianhelba wants to merge 2 commits intopytest-dev:mainfrom
--help/--version when conftest imports models#1275Conversation
|
@kingbuzzman I was able to fix this myself (and add a test to reproduce the failure). Could you please take a look? |
617176a to
022848c
Compare
Fixed upstream by: pytest-dev/pytest-django#1275
Fixed upstream by: pytest-dev/pytest-django#1275
Fixed upstream by: pytest-dev/pytest-django#1275
kingbuzzman
left a comment
There was a problem hiding this comment.
This is not a bad addition, please update the changelog.md
Previously, `pytest_load_initial_conftests` returned early when `--help` or `--version` was passed (added by pytest-dev#238), skipping `django.setup()` entirely. This caused conftest files with top-level Django model imports to fail with `AppRegistryNotReady`. Instead of returning early, continue with normal Django initialization, allowing `--help`/`--version` to return properly when everything is valid. If Django is somehow invalid (e.g. incorrect `DJANGO_SETTINGS_MODULE`), add a guard to still return gracefully if `--help`/`--version` is requested. Running real tests would still fail, but these basic informational arguments shouldn't be blocked. Fixes pytest-dev#1152
d6e1466 to
e016e08
Compare
|
@kingbuzzman Updated |
| ^^^^^^^^ | ||
|
|
||
| * Fixed type hints of assert methods to match actual signature (`PR #1271 <https://github.com/pytest-dev/pytest-django/pull/1271>`__) | ||
| * Fix Pytest `--help`/`--version` options when a `conftest.py` file imports Django models (`PR #1275 <https://github.com/pytest-dev/pytest-django/pull/1275>`__). |
There was a problem hiding this comment.
I thought the issue was when your apps we'rent ready, and you didn't care because you were doing a --help
There was a problem hiding this comment.
Right now, if you have any kind of top-level model import in confest.py, running a --help will error out, which what this PR fixes.
There was a problem hiding this comment.
I'm open to feedback on how to better describe this.
The PR is essentially a fix to --help and --version. The models are just the trigger for the previous failure.
Previously,
pytest_load_initial_conftestsreturned early when--helpor--versionwas passed (added by #238), skippingdjango.setup()entirely. This caused conftest files with top-level Django model imports to fail withAppRegistryNotReady.Instead of returning early, continue with normal Django initialization, allowing
--help/--versionto return properly when everything is valid.If Django is somehow invalid (e.g. incorrect
DJANGO_SETTINGS_MODULE), add a guard to still return gracefully if--help/--versionis requested. Running real tests would still fail, but these basic informational arguments shouldn't be blocked.Fixes #1152