Skip to content

[master] AttributeError in filter_traceback: 'str' object has no attribute 'relto' #995

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

Closed
blueyed opened this issue Sep 12, 2015 · 21 comments
Labels
topic: reporting related to terminal output and user-facing messages and errors type: bug problem that needs to be addressed
Milestone

Comments

@blueyed
Copy link
Contributor

blueyed commented Sep 12, 2015

I am seeing the following error suddenly:

INTERNALERROR>   File "…/pytest/_pytest/python.py", line 36, in filter_traceback
INTERNALERROR>     return entry.path != cutdir1 and not entry.path.relto(cutdir2)
INTERNALERROR> AttributeError: 'str' object has no attribute 'relto'

Normally entry.path is of type <class 'py._path.local.LocalPath'>, but in this case it is not.

> …/pytest/_pytest/python.py(39)filter_traceback()
     38         import ipdb; ipdb.set_trace()
---> 39     return entry.path != cutdir1 and not entry.path.relto(cutdir2)
     40 

ipdb> entry.path
'<frozen importlib._bootstrap>'
ipdb> cutdir1
local('…/pyenv/project/lib/python3.4/site-packages/pluggy.py')
ipdb> cutdir2
local('…/pytest/_pytest')

Full traceback:

Traceback (most recent call last):
  File "…/pytest/_pytest/main.py", line 90, in wrap_session
    doit(config, session)
  File "…/pytest/_pytest/main.py", line 125, in _main
    config.hook.pytest_runtestloop(session=session)
  File "…/pyenv/project/lib/python3.4/site-packages/pluggy.py", line 724, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "…/pyenv/project/lib/python3.4/site-packages/pluggy.py", line 338, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "…/pyenv/project/lib/python3.4/site-packages/pluggy.py", line 333, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "…/pyenv/project/lib/python3.4/site-packages/pluggy.py", line 596, in execute
    res = hook_impl.function(*args)
  File "…/pytest/_pytest/main.py", line 145, in pytest_runtestloop
    item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
  File "…/pyenv/project/lib/python3.4/site-packages/pluggy.py", line 724, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "…/pyenv/project/lib/python3.4/site-packages/pluggy.py", line 338, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "…/pyenv/project/lib/python3.4/site-packages/pluggy.py", line 333, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "…/pyenv/project/lib/python3.4/site-packages/pluggy.py", line 595, in execute
    return _wrapped_call(hook_impl.function(*args), self.execute)
  File "…/pyenv/project/lib/python3.4/site-packages/pluggy.py", line 253, in _wrapped_call
    return call_outcome.get_result()
  File "…/pyenv/project/lib/python3.4/site-packages/pluggy.py", line 278, in get_result
    raise ex[1].with_traceback(ex[2])
  File "…/pyenv/project/lib/python3.4/site-packages/pluggy.py", line 264, in __init__
    self.result = func()
  File "…/pyenv/project/lib/python3.4/site-packages/pluggy.py", line 596, in execute
    res = hook_impl.function(*args)
  File "…/pytest/_pytest/runner.py", line 67, in pytest_runtest_protocol
    runtestprotocol(item, nextitem=nextitem)
  File "…/pytest/_pytest/runner.py", line 74, in runtestprotocol
    rep = call_and_report(item, "setup", log)
  File "…/pytest/_pytest/runner.py", line 123, in call_and_report
    report = hook.pytest_runtest_makereport(item=item, call=call)
  File "…/pyenv/project/lib/python3.4/site-packages/pluggy.py", line 724, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "…/pyenv/project/lib/python3.4/site-packages/pluggy.py", line 338, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "…/pyenv/project/lib/python3.4/site-packages/pluggy.py", line 333, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "…/pyenv/project/lib/python3.4/site-packages/pluggy.py", line 595, in execute
    return _wrapped_call(hook_impl.function(*args), self.execute)
  File "…/pyenv/project/lib/python3.4/site-packages/pluggy.py", line 249, in _wrapped_call
    wrap_controller.send(call_outcome)
  File "…/pytest/_pytest/skipping.py", line 170, in pytest_runtest_makereport
    rep = outcome.get_result()
  File "…/pyenv/project/lib/python3.4/site-packages/pluggy.py", line 278, in get_result
    raise ex[1].with_traceback(ex[2])
  File "…/pyenv/project/lib/python3.4/site-packages/pluggy.py", line 264, in __init__
    self.result = func()
  File "…/pyenv/project/lib/python3.4/site-packages/pluggy.py", line 596, in execute
    res = hook_impl.function(*args)
  File "…/pytest/_pytest/runner.py", line 229, in pytest_runtest_makereport
    style=item.config.option.tbstyle)
  File "…/pytest/_pytest/python.py", line 695, in _repr_failure_py
    style=style)
  File "…/pytest/_pytest/main.py", line 396, in _repr_failure_py
    self._prunetraceback(excinfo)
  File "…/pytest/_pytest/python.py", line 678, in _prunetraceback
    ntraceback = ntraceback.filter(filter_traceback)
  File "…/pyenv/project/lib/python3.4/site-packages/py/_code/code.py", line 299, in filter
    return Traceback(filter(fn, self))
  File "…/pyenv/project/lib/python3.4/site-packages/py/_code/code.py", line 260, in __init__
    list.__init__(self, tb)
  File "…/pytest/_pytest/python.py", line 36, in filter_traceback
    return entry.path != cutdir1 and not entry.path.relto(cutdir2)
AttributeError: 'str' object has no attribute 'relto'
@blueyed
Copy link
Contributor Author

blueyed commented Sep 12, 2015

With pytest 2.7.2 (instead of master), I see this error during setup of tests,
which seems to be what pytest-master fails to handle:

Traceback (most recent call last):
  File "…/pyenv/project/lib/python3.4/site-packages/pytest_django/plugin.py", line 284, in _django_db_marker
    request.getfuncargvalue('db')
  File "…/pyenv/project/lib/python3.4/site-packages/_pytest/python.py", line 1385, in getfuncargvalue
    return self._get_active_fixturedef(argname).cached_result[0]
  File "…/pyenv/project/lib/python3.4/site-packages/_pytest/python.py", line 1402, in _get_active_fixturedef
    result = self._getfuncargvalue(fixturedef)
  File "…/pyenv/project/lib/python3.4/site-packages/_pytest/python.py", line 1448, in _getfuncargvalue
    val = fixturedef.execute(request=subrequest)
  File "…/pyenv/project/lib/python3.4/site-packages/_pytest/python.py", line 1880, in execute
    fixturedef = request._get_active_fixturedef(argname)
  File "…/pyenv/project/lib/python3.4/site-packages/_pytest/python.py", line 1402, in _get_active_fixturedef
    result = self._getfuncargvalue(fixturedef)
  File "…/pyenv/project/lib/python3.4/site-packages/_pytest/python.py", line 1448, in _getfuncargvalue
    val = fixturedef.execute(request=subrequest)
  File "…/pyenv/project/lib/python3.4/site-packages/_pytest/python.py", line 1893, in execute
    py.builtin._reraise(*err)
  File "…/pyenv/project/lib/python3.4/site-packages/py/_builtin.py", line 227, in _reraise
    raise cls.with_traceback(val, tb)
  File "…/pyenv/project/lib/python3.4/site-packages/_pytest/python.py", line 1914, in execute
    self.yieldctx)
  File "…/pyenv/project/lib/python3.4/site-packages/_pytest/python.py", line 1839, in call_fixture_func
    res = fixturefunc(**kwargs)
  File "…/pyenv/project/lib/python3.4/site-packages/pytest_django/fixtures.py", line 53, in _django_db_setup
    db_cfg = setup_databases(verbosity=0, interactive=False)
  File "…/django18/django/test/runner.py", line 370, in setup_databases
    serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
  File "…/django18/django/db/backends/base/creation.py", line 368, in create_test_db
    test_flush=not keepdb,
  File "…/django18/django/core/management/__init__.py", line 120, in call_command
    return command.execute(*args, **defaults)
  File "…/django18/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "…/django18/django/core/management/commands/migrate.py", line 93, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "…/django18/django/db/migrations/executor.py", line 19, in __init__
    self.loader = MigrationLoader(self.connection)
  File "…/django18/django/db/migrations/loader.py", line 47, in __init__
    self.build_graph()
  File "…/django18/django/db/migrations/loader.py", line 176, in build_graph
    self.load_disk()
  File "…/django18/django/db/migrations/loader.py", line 102, in load_disk
    migration_module = import_module("%s.%s" % (module_name, migration_name))
  File "…/pyenv/project/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "…/app/migrations/0051_auto_20150911_1517.py", line 22, in <module>
    class Migration(migrations.Migration):
  File "…/app/migrations/0051_auto_20150911_1517.py", line 32, in Migration
    field=models.ForeignKey(to='app.Organization',
NameError: name 'models' is not defined

@blueyed blueyed changed the title AttributeError in filter_traceback: 'str' object has no attribute 'relto' [master] AttributeError in filter_traceback: 'str' object has no attribute 'relto' Sep 12, 2015
@nicoddemus
Copy link
Member

Hi @blueyed,

Could you try the patch at https://bitbucket.org/pytest-dev/py/pull-requests/31? Seems related.

@RonnyPfannschmidt RonnyPfannschmidt modified the milestones: 2.8, 2.8.dev Sep 13, 2015
@ColtonProvias
Copy link

I'm having the exact same error and the patch did not work.

Python 3.5.0 running in virtualenv, on Mac OS X 10.11 Beta 6

==================================================================================================================================================== test session starts =====================================================================================================================================================
platform darwin -- Python 3.5.0, pytest-2.8.0, py-1.4.30, pluggy-0.3.1
rootdir: /Users/coltonprovias/Development/MyNewLeaf, inifile: pytest.ini
collected 61 items 

tests/test_api_admin_logs.py 
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/main.py", line 90, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/main.py", line 121, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/main.py", line 146, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 595, in execute
INTERNALERROR>     return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 253, in _wrapped_call
INTERNALERROR>     return call_outcome.get_result()
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 278, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 264, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/runner.py", line 65, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/runner.py", line 72, in runtestprotocol
INTERNALERROR>     rep = call_and_report(item, "setup", log)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/runner.py", line 121, in call_and_report
INTERNALERROR>     report = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 595, in execute
INTERNALERROR>     return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 249, in _wrapped_call
INTERNALERROR>     wrap_controller.send(call_outcome)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/skipping.py", line 170, in pytest_runtest_makereport
INTERNALERROR>     rep = outcome.get_result()
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 278, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 264, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/runner.py", line 227, in pytest_runtest_makereport
INTERNALERROR>     style=item.config.option.tbstyle)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/python.py", line 715, in _repr_failure_py
INTERNALERROR>     style=style)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/main.py", line 397, in _repr_failure_py
INTERNALERROR>     self._prunetraceback(excinfo)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/python.py", line 698, in _prunetraceback
INTERNALERROR>     ntraceback = ntraceback.filter(filter_traceback)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/py/_code/code.py", line 299, in filter
INTERNALERROR>     return Traceback(filter(fn, self))
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/py/_code/code.py", line 260, in __init__
INTERNALERROR>     list.__init__(self, tb)
INTERNALERROR>   File "/Users/coltonprovias/Development/MyNewLeaf/lib/python3.5/site-packages/_pytest/python.py", line 49, in filter_traceback
INTERNALERROR>     return entry.path != cutdir1 and not entry.path.relto(cutdir2)
INTERNALERROR> AttributeError: 'str' object has no attribute 'relto'

======================================================================================================================================================  in 0.41 seconds ======================================================================================================================================================

@The-Compiler
Copy link
Member

@blueyed @ColtonProvias Do you have a minimal example or a public project where this happens?

@nicoddemus
Copy link
Member

Perhaps it would be best for pytest to be on the safe side in this situation and guarantee that entry.path is always a py.path.local object:

entry_path = py.path.local(entry.path)
return entry_path != cutdir1 and not entry_path.relto(cutdir2)

Either way, it would be nice to get a minimal example, or at least a public project where the error is easily reproducible. 😅

@astraw38
Copy link

I'm starting to see this now as well, I'll try to get some more debug info:

entry = " File '<string>':2 in installed_client\n ???\n"

Where installed_client is a fixture in which the exception was raised.

And here is some of the stack:

00 = {str} 'frame: installed_client [<string>:2]  id:3009033612'
01 = {str} 'frame: call_fixture_func [python.py:1960]  id:3009275820'
02 = {str} 'frame: execute [python.py:2042]  id:3008955612'
03 = {str} 'frame: _getfuncargvalue [python.py:1582]  id:3009007092'
04 = {str} 'frame: _get_active_fixturedef [python.py:1532]  id:3009757604'
05 = {str} 'frame: execute [python.py:2001]  id:3008954812'
06 = {str} 'frame: _getfuncargvalue [python.py:1582]  id:3009671996'
07 = {str} 'frame: _get_active_fixturedef [python.py:1532]  id:3009744228'
08 = {str} 'frame: getfuncargvalue [python.py:1515]  id:3009283468'

@astraw38
Copy link

I believe the issue is using the decorator package (https://pypi.python.org/pypi/decorator).

I am using it to preserve certain fixtures signatures while attaching an additional decorator to it. From the documentation of decorator:

Calling f() will give you a ZeroDivisionError, but since the function is decorated the traceback will be longer:

>>> f()
Traceback (most recent call last):
  ...
     File "<string>", line 2, in f
     File "<doctest __main__[22]>", line 4, in trace
       return f(*args, **kw)
     File "<doctest __main__[51]>", line 3, in f
       1/0
ZeroDivisionError: ...

You see here the inner call to the decorator trace, which calls f(_args, *_kw), and a reference to File "", line 2, in f. This latter reference is due to the fact that internally the decorator module uses exec to generate the decorated function. Notice that exec is not responsibile for the performance penalty, since is the called only once at function decoration time, and not every time the decorated function is called.

@asfaltboy
Copy link

In my case, running on python 3.4, the AttributeError above was hiding another issue (discovered by using pytest==2.7.3); a mock/six.wraps discrepancy, which was fixed in mock 1.1.

After upgrading my mock to ver 1.3 I was also able to use pytest==2.8 again. IMHO it seems the real issue is the obscuring of underlying exception introduced in 2.8

@deuxpi
Copy link

deuxpi commented Sep 25, 2015

Recently we had a session level fixture that started failing. The error message in 2.7.3 was correct and helpful (with the complete description "ERROR as setup of ...."), but in 2.8.0 we just had a stack trace ending with

INTERNALERROR>   File ".../.tox/py27/local/lib/python2.7/site-packages/_pytest/python.py", line 49, in filter_traceback
INTERNALERROR>     return entry.path != cutdir1 and not entry.path.relto(cutdir2)
INTERNALERROR> AttributeError: 'str' object has no attribute 'relto'

Simply correcting the external condition that was causing the fixture to fail (which is actually to create some particular directory) fixes the problem. That fixture uses a decorator:

@pytest.fixture(scope='session')
def sc():
    spark_home = os.environ['SPARK_HOME']
    sys.path.insert(0, os.path.join(spark_home, 'python'))
    sys.path.insert(0, os.path.join(spark_home, 'python/lib/py4j-0.8.2.1-src.zip'))
    import pyspark
    return pyspark.SparkContext('local', 'tests')

@blueyed blueyed added type: bug problem that needs to be addressed topic: reporting related to terminal output and user-facing messages and errors labels Sep 25, 2015
@jonathanjfshaw
Copy link

I got the same as @deuxpi, an error from code being called inside a fixture is hidden by this "AttributeError: 'str' object has no attribute 'relto'" error.

Sorry nothing reproducible, but FWIW my structure is:

high/conftest.py
    def pytest_generate_tests(metafunc):
        if 'fixture1 in metafunc.fixturenames:
            metafunc.parametrize('fixture1', getSomeParams(metafunc), indirect=True)
        if 'fixture2' in metafunc.fixturenames:
            metafunc.parametrize('fixture2', ['string1','string2'])

    def getSomeParams(metafunc):
        return [someParams]

    @pytest.fixture()
    def fixture1(request, tmpdir):
        from myapp import myappexecute
        myappexecute()
        output=numpy.genfromtxt(blah) # load output file generated by app
        return output

low/verylow/test_mytest.py
    def test_mytest(fixture1,fixture2):
        assert something

The triggering error in my app (discovered when examining outside of pytest) is:
oid = h5o.open(self.id, self._e(name), lapl=self._lapl)
File "h5o.pyx", line 183, in h5py.h5o.open (h5py\h5o.c:3410)
KeyError: "Unable to open object (Object 'dataset' doesn't exist)"

@RonnyPfannschmidt RonnyPfannschmidt modified the milestones: 2.8.2, 2.8.1 Sep 27, 2015
@astraw38
Copy link

Here is a simple gist that will trigger the error:

https://gist.github.com/astraw38/e485eb89cf6cf61c7be9

The 'traceback.cut()' method does not filter out the _pytest internal code if you have an anonymous function in a different file.

@nicoddemus
Copy link
Member

Thanks @astraw38, that helped me narrow down a simple test case and fix the issue. 😄

RonnyPfannschmidt added a commit that referenced this issue Oct 1, 2015
Fix internal error when filtering tracebacks where one entry was generated by an exec() statement
Fixes #995
@jaraco
Copy link
Contributor

jaraco commented Nov 12, 2015

We're still seeing this error message running against pytest 2.8.2, so it may not be fixed.

@jaraco
Copy link
Contributor

jaraco commented Nov 12, 2015

Here is the traceback we see:

============================= test session starts ==============================
platform linux2 -- Python 2.7.6, pytest-2.8.2, py-1.4.30, pluggy-0.3.1
rootdir: /var/lib/jenkins/jobs/yg.ldap/workspace, inifile: pytest.ini
collected 29 items

yg/ldap/tests/test_commands.py 
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/main.py", line 90, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/main.py", line 121, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/main.py", line 146, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 595, in execute
INTERNALERROR>     return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 253, in _wrapped_call
INTERNALERROR>     return call_outcome.get_result()
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 279, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 264, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/runner.py", line 65, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/runner.py", line 72, in runtestprotocol
INTERNALERROR>     rep = call_and_report(item, "setup", log)
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/runner.py", line 121, in call_and_report
INTERNALERROR>     report = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 595, in execute
INTERNALERROR>     return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 249, in _wrapped_call
INTERNALERROR>     wrap_controller.send(call_outcome)
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/skipping.py", line 170, in pytest_runtest_makereport
INTERNALERROR>     rep = outcome.get_result()
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 279, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 264, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/runner.py", line 227, in pytest_runtest_makereport
INTERNALERROR>     style=item.config.option.tbstyle)
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/python.py", line 725, in _repr_failure_py
INTERNALERROR>     style=style)
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/main.py", line 397, in _repr_failure_py
INTERNALERROR>     self._prunetraceback(excinfo)
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/python.py", line 708, in _prunetraceback
INTERNALERROR>     ntraceback = ntraceback.filter(filter_traceback)
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/py-1.4.30-py2.7.egg/py/_code/code.py", line 299, in filter
INTERNALERROR>     return Traceback(filter(fn, self))
INTERNALERROR>   File "/var/lib/jenkins/jobs/yg.ldap/workspace/.eggs/pytest-2.8.2-py2.7.egg/_pytest/python.py", line 59, in filter_traceback
INTERNALERROR>     return entry.path != cutdir1 and not entry.path.relto(cutdir2)
INTERNALERROR> AttributeError: 'str' object has no attribute 'relto'

===============================  in 1.37 seconds ===============================

Interestingly, I'm unable to replicate the issue on my local workstation which is OS X and Python 2.7.10. I'll continue to troubleshoot until I can narrow down a cause. In the meantime, can you suggest a way to inspect the failure where it does exist?

@blueyed
Copy link
Contributor Author

blueyed commented Nov 12, 2015

@jaraco

can you suggest a way to inspect the failure where it does exist?

Can you use import ipdb; ipdb.set_trace() there, or is it on CI?

@nicoddemus
Copy link
Member

I'm pretty sure this has been fixed in #1142, but that's not out yet, unfortunately. @jaraco could you try with the latest master?

@jaraco
Copy link
Contributor

jaraco commented Nov 12, 2015

@nicoddemus Thanks for the hint. Yes. It works in the latest master. Thanks.

@dan-blanchard
Copy link

Will there be a release with this fix anytime soon? I keep running into this.

@nicoddemus
Copy link
Member

This should have been out in 2.8.3... which version are you using?

@dan-blanchard
Copy link

Sorry, was running an old version by accident!

@nicoddemus
Copy link
Member

Np! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: reporting related to terminal output and user-facing messages and errors type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests