thornomad
thornomad

Reputation: 6777

Upgrading pytest causes TypeError: 'NoneType' object is not callable error

Need help upgrading pytest. At 3.2.4 things work, if I move to 3.3.x or 3.4.x I get an error that I don't understand and I cannot even execute the -h argument. Not sure where to start or why this is happening. Perhaps an issue with my virtualenv ?

fresh virtualenv

I did try starting with a brand new fresh virtualenv, however, I still get the same error. Reverting to 3.2.4 fixes it.

working:

$ pytest --version
This is pytest version 3.2.4, imported from /Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/pytest.py

upgrade to 3.3.x

$ pytest --version
This is pytest version 3.3.2, imported from /Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/pytest.py

$ pytest --help
Traceback (most recent call last):
  File "/Users/me/.virtualenvs/hitcount/bin/pytest", line 11, in <module>
    sys.exit(main())
  File "/Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/_pytest/config.py", line 59, in main
    return config.hook.pytest_cmdline_main(config=config)
  File "/Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/pluggy/__init__.py", line 617, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/pluggy/__init__.py", line 222, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/pluggy/__init__.py", line 216, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File "/Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/pluggy/callers.py", line 201, in _multicall
    return outcome.get_result()
  File "/Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/pluggy/callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/pluggy/callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "/Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/_pytest/helpconfig.py", line 102, in pytest_cmdline_main
    config._do_configure()
  File "/Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/_pytest/config.py", line 921, in _do_configure
    self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
  File "/Users/me/.virtualenvs/hitcount/lib/python3.5/site-packages/pluggy/__init__.py", line 630, in call_historic
    proc(x)
TypeError: 'NoneType' object is not callable

source:

This is for an open source project I maintain: https://github.com/thornomad/django-hitcount

Upvotes: 4

Views: 3191

Answers (2)

Lokesh Murge
Lokesh Murge

Reputation: 11

By Upgrading pytest to 4.0.1 , This issue can be solved. The latest version of pytest >5.1 is not compatible with python >3.4.

Upvotes: 0

hoefling
hoefling

Reputation: 66281

What you encountered is a bug not in pytest, but in the plugin library it's based on, pluggy. The bug was fixed 2 months ago (see this commit), but unfortunately, the currently last version of pluggy (0.6.0) does not contain this fix.

You thus have two possibilities:

Depend on pluggy snapshot

This is the least invasive one. pytest does not require a strict version of pluggy, so just require the development version until the next pluggy release:

# tests/requirements.txt

coverage==4.5.1
flake8==2.5.4
mock==2.0.0
pytest==3.4.2
pytest-django==3.1.2
selenium==3.10.0
tox==2.9.1
# add some meaningful explanation here 
# so you don't forget why you need this particular snapshot of pluggy
git+https://github.com/pytest-dev/pluggy@dcde058f93a509b9c39409fca02100e43bb43485

Once the next version is released, remove the snapshot dependency and bump:

pluggy>0.6.0

Adapt pytest_configure hook

Adapt your pytest_configure hook so it does not return anything:

def configure():
    from django.conf import settings

    settings.configure(
        ...

    return settings

def pytest_configure():
    configure()

Don't forget to call the configure() function in runtests.py instead of pytest_configure() and you're good to go. However, this would be only a temporary workaround that can be reverted once pluggy>0.6.0 is released.

Upvotes: 4

Related Questions