Skip to content
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

Error when trying to migrate from python manage.py test to pytest #3347

Closed
4 tasks done
vinigfer opened this issue Mar 27, 2018 · 7 comments
Closed
4 tasks done

Error when trying to migrate from python manage.py test to pytest #3347

vinigfer opened this issue Mar 27, 2018 · 7 comments
Labels
type: question general question, might be closed after 2 weeks of inactivity

Comments

@vinigfer
Copy link

I believe I made all the necessary configurations to run the test using pytest, but still I'm getting an error message that is not exactly clear or helpfull at all. When I try to run the tests using tox command, I get the following:

(env) vagrant@localhost vagrant (pytest) $ tox
unit installed: alabaster==0.7.10,amqp==1.4.9,anyjson==0.3.3,astroid==1.3.2,attrs==16.1.0,Babel==2.5.3,billiard==3.3.0.23,boto3==1.5.18,botocore==1.8.50,celery==3.1.25,certifi==2018.1.18,chardet==3.0.4,codebakers==1.0.2,coverage==4.3.4,coveralls==1.1,Django==1.8.19,django-appconf==1.0.2,django-autoslug==1.7.2,django-bootstrap-breadcrumbs==0.8.2,django-cities-light==3.1.2,django-compressor==1.6,django-debug-toolbar==1.5,django-decorator-include==0.1,django-extensions==1.5.6,django-formset-js==0.4.3,django-jenkins==0.18.1,django-jquery-js==3.1.1,django-mptt==0.7.4,django-otp==0.4.0.1,django-parsley==0.6,django-pjax==1.3,django-polymorphic==0.7.2,django-polymorphic-tree==1.1.1,django-reversion==1.9.3,django-simple-email-confirmation==0.12,django-tag-parser==3.1,django-tokenapi==1.0.1,django-waffle==0.11.1,django-widget-tweaks==1.4.1,djangorestframework==3.5.2,DjPj==0.4.0,docopt==0.6.2,docutils==0.14,ecdsa==0.13,Fabric==1.8.3,flake8==2.4.0,flake8-import-order==0.6,funcsigs==1.0.2,future==0.16.0,futures==3.2.0,gevent==1.2.1,greenlet==0.4.13,idna==2.6,ipaddress==1.0.16,Jinja2==2.10,jmespath==0.9.3,kombu==3.0.37,linecache2==1.0.0,logilab-common==1.4.1,MarkupSafe==1.0,mccabe==0.3.1,mock==1.3.0,model-mommy==1.2.6,msgpack-python==0.4.8,parameterized==0.6.1,paramiko==1.12.4,pbr==4.0.0,pep8==1.5.7,pep8-naming==0.2.2,pluggy==0.6.0,py==1.5.3,pycrypto==2.6.1,pyflakes==0.8.1,Pygments==2.2.0,pylint==1.1.0,PyMySQL==0.7.11,pytest==3.4.2,pytest-django==3.1.2,python-dateutil==2.2,python-memcached==1.53,python-pcre==0.7,pytz==2018.3,pyzmq==16.0.2,qrcode==5.3,requests==2.18.4,requests-aws==0.1.8,rgwadmin==1.2.0,s3transfer==0.1.13,six==1.11.0,snowballstemmer==1.2.1,Sphinx==1.3.1,sphinx-rtd-theme==0.1.7,sqlparse==0.2.4,tldextract==1.7.2,tox==2.9.1,traceback2==1.4.0,typing==3.5.2.2,unicodecsv==0.14.1,Unidecode==1.0.22,unittest2==1.1.0,urllib3==1.22,virtualenv==15.2.0,Werkzeug==0.9.4,zerorpc==0.6.0
unit runtests: PYTHONHASHSEED='1097968999'
unit runtests: commands[0] | pytest
Traceback (most recent call last):
  File "/vagrant/.tox/unit/bin/pytest", line 7, in <module>
    from pytest import main
  File "/vagrant/.tox/unit/lib/python2.7/site-packages/pytest.py", line 13, in <module>
    from _pytest.fixtures import fixture, yield_fixture
  File "/vagrant/.tox/unit/lib/python2.7/site-packages/_pytest/fixtures.py", line 845, in <module>
    class FixtureFunctionMarker(object):
  File "/vagrant/.tox/unit/lib/python2.7/site-packages/_pytest/fixtures.py", line 847, in FixtureFunctionMarker
    params = attr.ib(convert=attr.converters.optional(tuple))
AttributeError: 'module' object has no attribute 'converters'
ERROR: InvocationError: '/vagrant/.tox/unit/bin/pytest'
__________________________________________________________ summary __________________________________________________________
ERROR:   unit: commands failed

and when I run only using pytest, I get the following:

(env) vagrant@localhost vagrant (pytest) $ pytest 
Traceback (most recent call last):
  File "/vagrant/env/bin/pytest", line 11, in <module>
    sys.exit(main())
  File "/vagrant/env/lib/python2.7/site-packages/_pytest/config.py", line 50, in main
    config = _prepareconfig(args, plugins)
  File "/vagrant/env/lib/python2.7/site-packages/_pytest/config.py", line 161, in _prepareconfig
    pluginmanager=pluginmanager, args=args)
  File "/vagrant/env/lib/python2.7/site-packages/pluggy/__init__.py", line 617, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/vagrant/env/lib/python2.7/site-packages/pluggy/__init__.py", line 222, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/vagrant/env/lib/python2.7/site-packages/pluggy/__init__.py", line 216, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File "/vagrant/env/lib/python2.7/site-packages/pluggy/callers.py", line 196, in _multicall
    gen.send(outcome)
  File "/vagrant/env/lib/python2.7/site-packages/_pytest/helpconfig.py", line 68, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/vagrant/env/lib/python2.7/site-packages/pluggy/callers.py", line 77, in get_result
    _reraise(*ex)  # noqa
  File "/vagrant/env/lib/python2.7/site-packages/pluggy/callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "/vagrant/env/lib/python2.7/site-packages/_pytest/config.py", line 944, in pytest_cmdline_parse
    self.parse(args)
  File "/vagrant/env/lib/python2.7/site-packages/_pytest/config.py", line 1109, in parse
    self._preparse(args, addopts=addopts)
  File "/vagrant/env/lib/python2.7/site-packages/_pytest/config.py", line 1080, in _preparse
    args=args, parser=self._parser)
  File "/vagrant/env/lib/python2.7/site-packages/pluggy/__init__.py", line 617, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/vagrant/env/lib/python2.7/site-packages/pluggy/__init__.py", line 222, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/vagrant/env/lib/python2.7/site-packages/pluggy/__init__.py", line 216, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File "/vagrant/env/lib/python2.7/site-packages/pluggy/callers.py", line 201, in _multicall
    return outcome.get_result()
  File "/vagrant/env/lib/python2.7/site-packages/pluggy/callers.py", line 77, in get_result
    _reraise(*ex)  # noqa
  File "/vagrant/env/lib/python2.7/site-packages/pluggy/callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "/vagrant/env/lib/python2.7/site-packages/pytest_django/plugin.py", line 244, in pytest_load_initial_conftests
    dj_settings.DATABASES
  File "/vagrant/env/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
    self._setup(name)
  File "/vagrant/env/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup
    self._wrapped = Settings(settings_module)
  File "/vagrant/env/lib/python2.7/site-packages/django/conf/__init__.py", line 113, in __init__
    raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
(env) vagrant@localhost vagrant (pytest) $

What exactly does AttributeError: 'module' object has no attribute 'converters' means? What am I missing in my configurations? Here are some other informations:

  • pip list:
(env) vagrant@localhost vagrant (pytest) $ pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
alabaster (0.7.10)
amqp (1.4.9)
anyjson (0.3.3)
astroid (1.3.2)
attrs (17.4.0)
Babel (2.5.3)
billiard (3.3.0.23)
boto3 (1.5.18)
botocore (1.8.43)
celery (3.1.25)
certifi (2018.1.18)
chardet (3.0.4)
codebakers (1.0.2)
coverage (4.3.4)
coveralls (1.1)
Django (1.8.19)
django-appconf (1.0.2)
django-autoslug (1.7.2)
django-bootstrap-breadcrumbs (0.8.2)
django-cities-light (3.1.2)
django-compressor (1.6)
django-debug-toolbar (1.5)
django-decorator-include (0.1)
django-extensions (1.5.6)
django-formset-js (0.4.3)
django-jenkins (0.18.1)
django-jquery-js (3.1.1)
django-mptt (0.7.4)
django-otp (0.4.0.1)
django-parsley (0.6)
django-pjax (1.3)
django-polymorphic (0.7.2)
django-polymorphic-tree (1.1.1)
django-reversion (1.9.3)
django-simple-email-confirmation (0.12)
django-tag-parser (3.1)
django-tokenapi (1.0.1)
django-waffle (0.11.1)
django-widget-tweaks (1.4.1)
djangorestframework (3.5.2)
DjPj (0.4.0)
docopt (0.6.2)
docutils (0.14)
ecdsa (0.13)
Fabric (1.8.3)
flake8 (2.4.0)
flake8-import-order (0.6)
funcsigs (1.0.2)
future (0.16.0)
futures (3.2.0)
gevent (1.2.1)
greenlet (0.4.13)
idna (2.6)
ipaddress (1.0.16)
Jinja2 (2.10)
jmespath (0.9.3)
kombu (3.0.37)
linecache2 (1.0.0)
logilab-common (1.4.1)
MarkupSafe (1.0)
mccabe (0.3.1)
mock (1.3.0)
model-mommy (1.2.6)
msgpack-python (0.4.8)
parameterized (0.6.1)
paramiko (1.12.4)
pbr (3.1.1)
pep8 (1.5.7)
pep8-naming (0.2.2)
pip (9.0.1)
pluggy (0.6.0)
py (1.5.2)
pycrypto (2.6.1)
pyflakes (0.8.1)
Pygments (2.2.0)
pylint (1.1.0)
PyMySQL (0.7.11)
pytest (3.4.2)
pytest-django (3.1.2)
python-dateutil (2.2)
python-memcached (1.53)
python-pcre (0.7)
pytz (2018.3)
pyzmq (16.0.2)
qrcode (5.3)
requests (2.18.4)
requests-aws (0.1.8)
rgwadmin (1.2.0)
s3transfer (0.1.13)
setuptools (38.5.1)
six (1.11.0)
snowballstemmer (1.2.1)
Sphinx (1.3.1)
sphinx-rtd-theme (0.1.7)
sqlparse (0.2.4)
tldextract (1.7.2)
tox (2.9.1)
traceback2 (1.4.0)
typing (3.5.2.2)
unicodecsv (0.14.1)
Unidecode (1.0.22)
unittest2 (1.1.0)
urllib3 (1.22)
virtualenv (15.1.0)
Werkzeug (0.9.4)
wheel (0.30.0)
zerorpc (0.6.0)
  • pytest version:
(env) vagrant@localhost vagrant (pytest) $ pytest --version
This is pytest version 3.4.2, imported from /vagrant/env/lib/python2.7/site-packages/pytest.pyc
setuptools registered plugins:
  pytest-django-3.1.2 at /vagrant/env/lib/python2.7/site-packages/pytest_django/plugin.py

Operating System is CentOS Linux release 7.4.1708 (Core) (inside a VM with Vagrant)

Also, here is the contents of my tox.ini

(env) vagrant@localhost vagrant (pytest) $ cat tox.ini 
[tox]
envlist = unit
skipsdist = True

[testenv:unit]
deps = -rrequirements/development.txt
commands =
    pytest
passenv = *
setenv =
    DJANGO_SETTINGS_MODULE = myproject.settings
    SECRET_KEY = 'reallyrandomstuffthatIreplacedhere'
    CELERY_ALWAYS_EAGER = True

and also here is the contents of my pytest.ini:

(env) vagrant@localhost vagrant (pytest) $ cat pytest.ini 
[pytest]
DJANGO_SETTINGS_MODULE=myproject.settings
SECRET_KEY = '**********'
CELERY_ALWAYS_EAGER = True
python_files=**/tests.py
norecursedirs = requirements .tox media
  • Include a detailed description of the bug or suggestion
  • pip list of the virtual environment you are using
  • pytest and operating system versions
  • Minimal example if possible
@pytestbot pytestbot added the type: bug problem that needs to be addressed label Mar 27, 2018
@pytestbot
Copy link
Contributor

GitMate.io thinks possibly related issues are #1685 (python setup.py test fails to install pytest), #3245 (py.test on pytest fails when not limiting to the testing folder), #18 (pytest-2.0.0 fails testing/test_nose.py on python-3.1.3), #3163 (Pytest internal error due to infinite recursion on final test), and #1484 (running py.test).

@blueyed blueyed added type: question general question, might be closed after 2 weeks of inactivity and removed type: bug problem that needs to be addressed labels Mar 27, 2018
@blueyed
Copy link
Contributor

blueyed commented Mar 27, 2018

File "/vagrant/.tox/unit/lib/python2.7/site-packages/_pytest/fixtures.py", line 847, in FixtureFunctionMarker
params = attr.ib(convert=attr.converters.optional(tuple))
AttributeError: 'module' object has no attribute 'converters'

This looks like an incompatible version of attrs.

File "/vagrant/env/lib/python2.7/site-packages/django/conf/init.py", line 113, in init
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

You seem to not have configured Django correctly - the SECRET_KEY is not defined in the settings?!

@vinigfer
Copy link
Author

SECRET_KEY:
It is set both in pytest.ini and tox.ini
The error refering SECRET_KEY doesnt happen when I use tox

@blueyed
Copy link
Contributor

blueyed commented Mar 27, 2018

It looks like tox might crash earlier already.
How do you set the secret key? Through an env var picked up in your settings?
Add some __import__('pdb').set_trace() into your settings and see if/when it comes there.

@RonnyPfannschmidt
Copy link
Member

as first part, please upgrade attrs or downgrade pytest - its required for compatibility

@alejandrodnm
Copy link

I had the same problem, but with Travis CI. In my local machine worked fine, but Travis started giving me that error after upgrading to pytest 3.5.0.

I had to pin attrs to 17.4.0 in my requirements to solve the problem, a dependency called service_identity was installing attrs=17.3.0 which made pytest crash.

@nicoddemus
Copy link
Member

Yeah, it seems another case where pip's dependency solver did not yield correct results. 😕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

6 participants