chmp / ipytest

Pytest in IPython notebooks.
MIT License
314 stars 17 forks source link

Error Executing Ipytest with Anaconda #41

Closed smileykaur closed 4 years ago

smileykaur commented 4 years ago

Hi, I am trying to run ipytest on a notebook in Jupyter lab on AWS server -

import pytest
import ipytest
ipytest.autoconfig()

def my_func(x):
    return x // 2 * 2

def test_my_func():
    assert my_func(0) == 0
    assert my_func(1) == 0
    assert my_func(2) == 2
    assert my_func(3) == 2

ipytest.run('-qq') 

I get error AttributeError: 'super' object has no attribute 'from_parent'. When I run the same code on a local Jupyter notebook this runs successfully.

==================================== ERRORS ====================================
________________________ ERROR collecting test session _________________________
/opt/anaconda3/lib/python3.7/site-packages/pluggy/hooks.py:286: in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
/opt/anaconda3/lib/python3.7/site-packages/pluggy/manager.py:92: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
/opt/anaconda3/lib/python3.7/site-packages/pluggy/manager.py:86: in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
ipytest/ipytest/_pytest_support.py:144: in pytest_collect_file
    parent, fspath=path.new(ext=".py"), module=self.module
ipytest/ipytest/_pytest_support.py:157: in from_parent
    self = super(pytest.Module).from_parent(parent, fspath=fspath)
E   AttributeError: 'super' object has no attribute 'from_parent'
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!
smileykaur commented 4 years ago

The above issue occur with Python 3.7.4, when using ipytest-0.8.1 with Pytest 5.2.1. After updating Pytest to v5.4.1 this issue gets resolved.

chmp commented 4 years ago

Thanks for reporting this issue. TBH. the current requirement spec is suboptimal. In the next release of ipytest, pytest will a proper requirement and this problem will solve itself automatically.

Thanks for figuring out that not all versions of pytest 5.x.x support from_parent. I was not aware :)

Edit: browsing the changelog of pytest -- they changed the behavior in version 5.4.0