pytest-dev / pytest-django

A Django plugin for pytest.
https://pytest-django.readthedocs.io/
Other
1.32k stars 341 forks source link

4.7.0: pytest is failing because missing `pytest_django_test` module #1096

Closed kloczek closed 7 months ago

kloczek commented 7 months ago

Here is pytest output:

```console + PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-django-4.7.0-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-django-4.7.0-2.fc35.x86_64/usr/lib/python3.8/site-packages + /usr/bin/pytest -ra -m 'not network' tests --pyargs pytest_django_test Traceback (most recent call last): File "/usr/bin/pytest", line 8, in sys.exit(console_main()) File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 192, in console_main code = main() File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 150, in main config = _prepareconfig(args, plugins) File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 331, in _prepareconfig config = pluginmanager.hook.pytest_cmdline_parse( File "/usr/lib/python3.8/site-packages/pluggy/_hooks.py", line 493, in __call__ return self._hookexec(self.name, self._hookimpls, kwargs, firstresult) File "/usr/lib/python3.8/site-packages/pluggy/_manager.py", line 115, in _hookexec return self._inner_hookexec(hook_name, methods, kwargs, firstresult) File "/usr/lib/python3.8/site-packages/pluggy/_callers.py", line 130, in _multicall teardown[0].send(outcome) File "/usr/lib/python3.8/site-packages/_pytest/helpconfig.py", line 104, in pytest_cmdline_parse config: Config = outcome.get_result() File "/usr/lib/python3.8/site-packages/pluggy/_result.py", line 114, in get_result raise exc.with_traceback(exc.__traceback__) File "/usr/lib/python3.8/site-packages/pluggy/_callers.py", line 77, in _multicall res = hook_impl.function(*args) File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1075, in pytest_cmdline_parse self.parse(args) File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1425, in parse self._preparse(args, addopts=addopts) File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1327, in _preparse self.hook.pytest_load_initial_conftests( File "/usr/lib/python3.8/site-packages/pluggy/_hooks.py", line 493, in __call__ return self._hookexec(self.name, self._hookimpls, kwargs, firstresult) File "/usr/lib/python3.8/site-packages/pluggy/_manager.py", line 115, in _hookexec return self._inner_hookexec(hook_name, methods, kwargs, firstresult) File "/usr/lib/python3.8/site-packages/pluggy/_callers.py", line 152, in _multicall return outcome.get_result() File "/usr/lib/python3.8/site-packages/pluggy/_result.py", line 114, in get_result raise exc.with_traceback(exc.__traceback__) File "/usr/lib/python3.8/site-packages/pluggy/_callers.py", line 77, in _multicall res = hook_impl.function(*args) File "/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-django-4.7.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_django/plugin.py", line 356, in pytest_load_initial_conftests dj_settings.DATABASES # noqa: B018 File "/usr/lib64/python3.8/contextlib.py", line 131, in __exit__ self.gen.throw(type, value, traceback) File "/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-django-4.7.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_django/plugin.py", line 183, in _handle_import_error raise ImportError(msg) from None ImportError: No module named 'pytest_django_test' pytest-django could not find a Django project (no manage.py file could be found). You must explicitly add your Django project to the Python path to have it picked up. ```

Looks like this module is in source tree in pytest_django_test/ however it is not build on pep517 build procedure or there is no any pytest options in pytest.ini or pyproject.toml to add use this module on testing. Any hints how testing should be done? 🤔

bluetech commented 7 months ago

You need to run pytest with PYTHONPATH=<absolute path to source code root>. Unfortunately using pytest's pythonpath config doesn't work because subprocesses are used in some tests. I've been meaning to fix this (it requires a fix in Pytester.popen in pytest) but haven't got to it.

kloczek commented 7 months ago

You need to run pytest with PYTHONPATH=<absolute path to source code root>. Unfortunately using pytest's pythonpath config doesn't work because subprocesses are used in some tests. I've been meaning to fix this (it requires a fix in Pytester.popen in pytest) but haven't got to it.

This will cause that it will be tested pytest-django from source tree. I think that probably the best would be merge pytest_django_test/ with tests/ 🤔

bluetech commented 7 months ago

This should be fixed in the next version