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

TypeError in python.py:_getobj when having a TestCase namedtuple #1579

Closed
languitar opened this issue Jun 1, 2016 · 12 comments
Closed

TypeError in python.py:_getobj when having a TestCase namedtuple #1579

languitar opened this issue Jun 1, 2016 · 12 comments
Labels
status: critical grave problem or usability issue that affects lots of users status: help wanted developers would like help from experts on this topic topic: collection related to the collection phase type: bug problem that needs to be addressed

Comments

@languitar
Copy link

parametrizing a test function fails in case the argument for the function is only an empty list:

@pytest.mark.parametrize('test_cases', [
    ([], )
])
def test_read_write_roundtrip(test_cases):
    pass

fails with:

/media/local_data/jwienke/miniconda2/envs/monitoring/lib/python2.7/site-packages/_pytest/runner.py:150: in __init__
    self.result = func()
/media/local_data/jwienke/miniconda2/envs/monitoring/lib/python2.7/site-packages/_pytest/main.py:435: in _memocollect
    return self._memoizedcall('_collected', lambda: list(self.collect()))
/media/local_data/jwienke/miniconda2/envs/monitoring/lib/python2.7/site-packages/_pytest/main.py:315: in _memoizedcall
    res = function()
/media/local_data/jwienke/miniconda2/envs/monitoring/lib/python2.7/site-packages/_pytest/main.py:435: in <lambda>
    return self._memoizedcall('_collected', lambda: list(self.collect()))
/media/local_data/jwienke/miniconda2/envs/monitoring/lib/python2.7/site-packages/_pytest/python.py:685: in collect
    self.session._fixturemanager.parsefactories(self)
/media/local_data/jwienke/miniconda2/envs/monitoring/lib/python2.7/site-packages/_pytest/python.py:1969: in parsefactories
    holderobj = node_or_obj.obj
/media/local_data/jwienke/miniconda2/envs/monitoring/lib/python2.7/site-packages/_pytest/python.py:351: in fget
    self._obj = obj = self._getobj()
/media/local_data/jwienke/miniconda2/envs/monitoring/lib/python2.7/site-packages/_pytest/python.py:681: in _getobj
    obj = self.parent.obj()
E   TypeError: __new__() takes exactly 4 arguments (1 given)
astroid (1.4.4)
backports.shutil-get-terminal-size (1.0.0)
backports.ssl-match-hostname (3.4.0.2)
coverage (4.1)
cycler (0.10.0)
decorator (4.0.9)
enum34 (1.1.3)
futures (3.0.5)
greenlet (0.4.9)
ipython (4.2.0)
ipython-genutils (0.1.0)
jenkinsapi (0.2.30)
junit-xml (1.6)
lazy-object-proxy (1.2.1)
loggerbyclass (0.2.0)
logilab-common (1.0.2)
matplotlib (1.5.1)
monitoring-lib (0.1.0)
msgpack-python (0.4.7)
neovim (0.1.7)
nose (1.3.7)
numexpr (2.5.2)
numpy (1.11.0)
pandas (0.18.1)
path.py (0.0.0)
patsy (0.4.1)
pep8 (1.7.0)
perfmonvalidation (0.3)
pexpect (4.0.1)
pickleshare (0.5)
pip (7.1.2)
protobuf (2.5.0)
ptyprocess (0.5)
py (1.4.31)
pybtex (0.19)
pycairo (1.10.0)
pylint (1.5.4)
pyparsing (2.1.1)
pytest (2.9.1)
python-dateutil (2.5.2)
pytz (2016.3)
requests (2.10.0)
rsb-python (0.13.0)
rsbag-python (0.13.1)
rst (0.13.0)
rstsandbox (0.13.0)
rststable (0.13.5)
scikit-learn (0.17.1)
scipy (0.17.1)
seaborn (0.7.0)
setuptools (20.7.0)
simplegeneric (0.8.1)
singledispatch (3.4.0.3)
six (1.10.0)
statsmodels (0.6.1)
tables (3.2.2)
traitlets (4.2.1)
trollius (2.1)
websocket-client (0.34.0)
wheel (0.29.0)
wrapt (1.10.6)

Running on ubuntu trusty 64 bit with miniconda python:

Python 2.7.11 :: Continuum Analytics, Inc.
@RonnyPfannschmidt
Copy link
Member

please test with version 2.9.2, it has a fix for #510 which could be related - else i#ll have to investigate deeper,
but the example is a perfect start in any case

@languitar
Copy link
Author

languitar commented Jun 1, 2016

Same thing with 2.9.2.

This also happens when building the cartesian product for multiple parameters:

@pytest.mark.parametrize(
    'test_cases',
    [[],
     [TestCase('dummy', '453123', pd.DataFrame({'test': [1]}))]])
@pytest.mark.parametrize(
    'counters_by_component',
    [{},
     {'test': pd.DataFrame({'ffoo': [4]})}])
@pytest.mark.parametrize('test_time', [pd.to_datetime('now')])
def test_read_write_roundtrip(tmpdir, test_cases, counters_by_component,
                              test_time):
    pass

Results in the same exception once the respective parameter combination is reached.

@languitar
Copy link
Author

And another case:

@pytest.mark.parametrize('foo', [None])
def test_read_write_roundtrip(foo):
    pass

@The-Compiler
Copy link
Member

FWIW I can't reproduce either of the minimal examples with Python 2.7.11 and pytest 2.9.2.

@languitar
Copy link
Author

So maybe it is miniconda-related?

@The-Compiler
Copy link
Member

I'd doubt it, but maybe I'm wrong 😉

Can you run with --collect-only or do you get the same error? And you're sure you don't get it when not doing the parametrization?

@languitar
Copy link
Author

Ok, I found what is causing this in my test file:

from perfmonvalidation.data import (TestCase)

@languitar
Copy link
Author

I can import that with a different name, but can't the name clash be avoided?

@RonnyPfannschmidt
Copy link
Member

__test__ = False in the class?

@The-Compiler
Copy link
Member

Okay, so it has nothing to do with @pytest.mark.parametrize at all then?

pytest will try to collect tests in all classes starting with Test..., but I still wouldn't expect it to blow up like this. Can you show how perfmonvalidation.data.TestCase looks?

@languitar
Copy link
Author

its a namedtuple

@The-Compiler
Copy link
Member

Reproduced with this test_x.py:

import collections
TestCase = collections.namedtuple('TestCase', ['a'])

Renaming the issue to avoid confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: critical grave problem or usability issue that affects lots of users status: help wanted developers would like help from experts on this topic topic: collection related to the collection phase type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

3 participants