py.test INTERNALERROR> IndexError: list index out of range
py.test INTERNALERROR> IndexError: list index out of range
我正在研究 Ubuntu 15.04:
平台linux -- Python 3.4.3, pytest-2.8.3, py-1.4.31, pluggy-0.3.1
rootdir: /home/barrios/code/testpytest, inifile:
在一个新的 virtualenv 中,我构建了以下项目结构:
myapp/
__init__.py
myapp.py
tests/
tests.py
setup.py
按照这里的各种帖子,我发现要么将 PYTHONPATH 设置为我的项目根目录,要么使用以下方式调用 py.test:
PYTHONPATH=. py.test tests/tests.py
myapp.py 看起来像这样:
class Foo:
def __init__(self):
self.bar = None
def set_bar(self, val):
self.bar = val
tests.py:
from myapp import Foo
class TestFoo:
def setup_method(self, method):
self.foo = Foo()
def teardown_method(self):
self.foo.bar = None
def test_set_bar(self):
self.foo.set_bar(7)
assert self.foo.bar is 7
阅读我也把这个放在我的__init__.py:
from .myapp import Foo
__all__ = ['Foo']
我能做到
>>> from myapp import Foo
在 python 控制台和
$> pip install -e .
来自终端。
但是 py.test 抱怨引发内部错误:
(venv)barrios@tuxedo:~/code/testpytest$ PYTHONPATH=. py.test tests/tests.py
=============================================================== test session starts ===============================================================
platform linux -- Python 3.4.3, pytest-2.8.3, py-1.4.31, pluggy-0.3.1
rootdir: /home/barrios/code/testpytest, inifile:
collected 1 items
tests/tests.py .
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/main.py", line 90, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/main.py", line 121, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/main.py", line 146, in pytest_runtestloop
INTERNALERROR> item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 595, in execute
INTERNALERROR> return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 253, in _wrapped_call
INTERNALERROR> return call_outcome.get_result()
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 278, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 264, in __init__
INTERNALERROR> self.result = func()
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/runner.py", line 65, in pytest_runtest_protocol
INTERNALERROR> runtestprotocol(item, nextitem=nextitem)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/runner.py", line 77, in runtestprotocol
INTERNALERROR> nextitem=nextitem))
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/runner.py", line 121, in call_and_report
INTERNALERROR> report = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 595, in execute
INTERNALERROR> return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 249, in _wrapped_call
INTERNALERROR> wrap_controller.send(call_outcome)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/skipping.py", line 170, in pytest_runtest_makereport
INTERNALERROR> rep = outcome.get_result()
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 278, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 264, in __init__
INTERNALERROR> self.result = func()
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/runner.py", line 227, in pytest_runtest_makereport
INTERNALERROR> style=item.config.option.tbstyle)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/python.py", line 740, in _repr_failure_py
INTERNALERROR> style=style)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/main.py", line 404, in _repr_failure_py
INTERNALERROR> style=style, tbfilter=tbfilter)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/py/_code/code.py", line 412, in getrepr
INTERNALERROR> return fmt.repr_excinfo(self)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/py/_code/code.py", line 590, in repr_excinfo
INTERNALERROR> reprtraceback = self.repr_traceback(excinfo)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/py/_code/code.py", line 577, in repr_traceback
INTERNALERROR> last = traceback[-1]
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/py/_code/code.py", line 284, in __getitem__
INTERNALERROR> val = super(Traceback, self).__getitem__(key)
INTERNALERROR> IndexError: list index out of range
我不太确定要在 py.test bugtracker 上报告问题,或者如果我仍然做错了什么?
您的拆卸方法缺少第二个参数,即 method
:
def teardown_method(self, method):
在此处仔细阅读文档:
https://pytest.org/latest/xunit_setup.html
我正在研究 Ubuntu 15.04:
平台linux -- Python 3.4.3, pytest-2.8.3, py-1.4.31, pluggy-0.3.1 rootdir: /home/barrios/code/testpytest, inifile:
在一个新的 virtualenv 中,我构建了以下项目结构:
myapp/
__init__.py
myapp.py
tests/
tests.py
setup.py
按照这里的各种帖子,我发现要么将 PYTHONPATH 设置为我的项目根目录,要么使用以下方式调用 py.test:
PYTHONPATH=. py.test tests/tests.py
myapp.py 看起来像这样:
class Foo:
def __init__(self):
self.bar = None
def set_bar(self, val):
self.bar = val
tests.py:
from myapp import Foo
class TestFoo:
def setup_method(self, method):
self.foo = Foo()
def teardown_method(self):
self.foo.bar = None
def test_set_bar(self):
self.foo.set_bar(7)
assert self.foo.bar is 7
阅读
from .myapp import Foo
__all__ = ['Foo']
我能做到
>>> from myapp import Foo
在 python 控制台和
$> pip install -e .
来自终端。
但是 py.test 抱怨引发内部错误:
(venv)barrios@tuxedo:~/code/testpytest$ PYTHONPATH=. py.test tests/tests.py
=============================================================== test session starts ===============================================================
platform linux -- Python 3.4.3, pytest-2.8.3, py-1.4.31, pluggy-0.3.1
rootdir: /home/barrios/code/testpytest, inifile:
collected 1 items
tests/tests.py .
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/main.py", line 90, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/main.py", line 121, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/main.py", line 146, in pytest_runtestloop
INTERNALERROR> item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 595, in execute
INTERNALERROR> return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 253, in _wrapped_call
INTERNALERROR> return call_outcome.get_result()
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 278, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 264, in __init__
INTERNALERROR> self.result = func()
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/runner.py", line 65, in pytest_runtest_protocol
INTERNALERROR> runtestprotocol(item, nextitem=nextitem)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/runner.py", line 77, in runtestprotocol
INTERNALERROR> nextitem=nextitem))
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/runner.py", line 121, in call_and_report
INTERNALERROR> report = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 595, in execute
INTERNALERROR> return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 249, in _wrapped_call
INTERNALERROR> wrap_controller.send(call_outcome)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/skipping.py", line 170, in pytest_runtest_makereport
INTERNALERROR> rep = outcome.get_result()
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 278, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 264, in __init__
INTERNALERROR> self.result = func()
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/runner.py", line 227, in pytest_runtest_makereport
INTERNALERROR> style=item.config.option.tbstyle)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/python.py", line 740, in _repr_failure_py
INTERNALERROR> style=style)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/_pytest/main.py", line 404, in _repr_failure_py
INTERNALERROR> style=style, tbfilter=tbfilter)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/py/_code/code.py", line 412, in getrepr
INTERNALERROR> return fmt.repr_excinfo(self)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/py/_code/code.py", line 590, in repr_excinfo
INTERNALERROR> reprtraceback = self.repr_traceback(excinfo)
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/py/_code/code.py", line 577, in repr_traceback
INTERNALERROR> last = traceback[-1]
INTERNALERROR> File "/home/barrios/code/testpytest/venv/lib/python3.4/site-packages/py/_code/code.py", line 284, in __getitem__
INTERNALERROR> val = super(Traceback, self).__getitem__(key)
INTERNALERROR> IndexError: list index out of range
我不太确定要在 py.test bugtracker 上报告问题,或者如果我仍然做错了什么?
您的拆卸方法缺少第二个参数,即 method
:
def teardown_method(self, method):
在此处仔细阅读文档: https://pytest.org/latest/xunit_setup.html