pytest-django icon indicating copy to clipboard operation
pytest-django copied to clipboard

4.8.0: pytest is failing

Open kloczek opened this issue 3 years ago • 4 comments
trafficstars

I'm trying to package your module as an rpm package. So I'm using the typical build, install and test cycle used on building packages from non-root account.

  • "setup.py build"
  • "setup.py install --root </install/prefix>"
  • "pytest with PYTHONPATH pointing to sitearch and sitelib inside </install/prefix>

pytest is failing because it cannot find pytest_django_test which is in project root directory. Is it any special methdod to preload that modules during the test suite execution?

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-django-4.5.1-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-django-4.5.1-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra tests
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 703, in import_plugin
    __import__(importspec)
ModuleNotFoundError: No module named 'pytest_django_test'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/bin/pytest", line 33, in <module>
    sys.exit(load_entry_point('pytest==6.2.5', 'console_scripts', 'pytest')())
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 185, in console_main
    code = main()
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 143, in main
    config = _prepareconfig(args, plugins)
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 318, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "/usr/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/usr/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "/usr/lib/python3.8/site-packages/pluggy/callers.py", line 203, in _multicall
    gen.send(outcome)
  File "/usr/lib/python3.8/site-packages/_pytest/helpconfig.py", line 100, in pytest_cmdline_parse
    config: Config = outcome.get_result()
  File "/usr/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1003, in pytest_cmdline_parse
    self.parse(args)
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1283, in parse
    self._preparse(args, addopts=addopts)
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1168, in _preparse
    self.pluginmanager.consider_preparse(args, exclude_only=False)
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 635, in consider_preparse
    self.consider_pluginarg(parg)
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 660, in consider_pluginarg
    self.import_plugin(arg, consider_entry_points=True)
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 705, in import_plugin
    raise ImportError(
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 703, in import_plugin
    __import__(importspec)
ImportError: Error importing plugin "pytest_django_test": No module named 'pytest_django_test'

kloczek avatar Dec 02 '21 11:12 kloczek

I've been trying to run pytest with --pyargs pytest_django_test but it did not helped. How pytest-django shoud be tested using pytest?

kloczek avatar Dec 31 '21 19:12 kloczek

gentle ping 😃

kloczek avatar May 14 '22 17:05 kloczek

I just had a similar problem when trying to test pytest-django on Solaris, and the problem was that pytest_django_test isn't being delivered, meaning that if you are running the test suite on installed packages or in proto area (which was our issue), it won't work. Adding the source directory to PYTHONPATH fixed the issue.

kulikjak avatar May 27 '22 08:05 kulikjak

Just tested 4.8.0 with django 5.03, python 3.9.18 and pytest 8.1.1 and now pytest fails other way

Here is pytest output:
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-django-4.8.0-2.fc36.x86_64/usr/lib64/python3.9/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-django-4.8.0-2.fc36.x86_64/usr/lib/python3.9/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 <module>
    sys.exit(console_main())
  File "/usr/lib/python3.9/site-packages/_pytest/config/__init__.py", line 197, in console_main
    code = main()
  File "/usr/lib/python3.9/site-packages/_pytest/config/__init__.py", line 155, in main
    config = _prepareconfig(args, plugins)
  File "/usr/lib/python3.9/site-packages/_pytest/config/__init__.py", line 337, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "/usr/lib/python3.9/site-packages/pluggy/_hooks.py", line 501, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "/usr/lib/python3.9/site-packages/pluggy/_manager.py", line 119, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/usr/lib/python3.9/site-packages/pluggy/_callers.py", line 138, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/usr/lib/python3.9/site-packages/pluggy/_callers.py", line 121, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "/usr/lib/python3.9/site-packages/_pytest/helpconfig.py", line 105, in pytest_cmdline_parse
    config = yield
  File "/usr/lib/python3.9/site-packages/pluggy/_callers.py", line 102, in _multicall
    res = hook_impl.function(*args)
  File "/usr/lib/python3.9/site-packages/_pytest/config/__init__.py", line 1143, in pytest_cmdline_parse
    self.parse(args)
  File "/usr/lib/python3.9/site-packages/_pytest/config/__init__.py", line 1492, in parse
    self._preparse(args, addopts=addopts)
  File "/usr/lib/python3.9/site-packages/_pytest/config/__init__.py", line 1396, in _preparse
    self.hook.pytest_load_initial_conftests(
  File "/usr/lib/python3.9/site-packages/pluggy/_hooks.py", line 501, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "/usr/lib/python3.9/site-packages/pluggy/_manager.py", line 119, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/usr/lib/python3.9/site-packages/pluggy/_callers.py", line 138, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/usr/lib/python3.9/site-packages/pluggy/_callers.py", line 121, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "/usr/lib/python3.9/site-packages/_pytest/warnings.py", line 150, in pytest_load_initial_conftests
    return (yield)
  File "/usr/lib/python3.9/site-packages/pluggy/_callers.py", line 121, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "/usr/lib/python3.9/site-packages/_pytest/capture.py", line 153, in pytest_load_initial_conftests
    yield
  File "/usr/lib/python3.9/site-packages/pluggy/_callers.py", line 102, in _multicall
    res = hook_impl.function(*args)
  File "/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-django-4.8.0-2.fc36.x86_64/usr/lib/python3.9/site-packages/pytest_django/plugin.py", line 361, in pytest_load_initial_conftests
    _setup_django(early_config)
  File "/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-django-4.8.0-2.fc36.x86_64/usr/lib/python3.9/site-packages/pytest_django/plugin.py", line 237, in _setup_django
    django.setup()
  File "/usr/lib/python3.9/site-packages/django/__init__.py", line 16, in setup
    from django.urls import set_script_prefix
  File "/usr/lib/python3.9/site-packages/django/urls/__init__.py", line 1, in <module>
    from .base import (
  File "/usr/lib/python3.9/site-packages/django/urls/base.py", line 8, in <module>
    from .exceptions import NoReverseMatch, Resolver404
  File "/usr/lib/python3.9/site-packages/django/urls/exceptions.py", line 1, in <module>
    from django.http import Http404
  File "/usr/lib/python3.9/site-packages/django/http/__init__.py", line 2, in <module>
    from django.http.request import (
  File "/usr/lib/python3.9/site-packages/django/http/request.py", line 8, in <module>
    from django.core import signing
  File "/usr/lib/python3.9/site-packages/django/core/signing.py", line 44, in <module>
    from django.utils.crypto import constant_time_compare, salted_hmac
  File "/usr/lib/python3.9/site-packages/django/utils/crypto.py", line 10, in <module>
    from django.utils.encoding import force_bytes
  File "/usr/lib/python3.9/site-packages/django/utils/encoding.py", line 5, in <module>
    from types import NoneType
ImportError: cannot import name 'NoneType' from 'types' (/usr/lib64/python3.9/types.py)

kloczek avatar Mar 18 '24 16:03 kloczek