$ pip list
pip (8.1.1)
py (1.4.31)
pytest (3.0.3)
setuptools (20.10.1)
import pytest
def my_func():
code = compile("", "name", "exec")
@pytest.mark.parametrize('eclass', [SyntaxError, ArithmeticError])
def test_my_func(monkeypatch, eclass):
def raise_ex(*args):
raise eclass()
monkeypatch.setattr('builtins.compile', raise_ex)
with pytest.raises(SyntaxError):
my_func()
$ py.test -v example.py
============================== test session starts ===============================
platform darwin -- Python 3.5.2, pytest-3.0.3, py-1.4.31, pluggy-0.4.0 -- /Users/surana/Projects/tmp/pytesting/bin/python3.5
cachedir: .cache
rootdir: /Users/surana/Projects/tmp/pytesting, inifile:
collected 2 items
example.py::test_my_func[SyntaxError] PASSED
example.py::test_my_func[ArithmeticError]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/main.py", line 96, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/main.py", line 131, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 745, in __call__
INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 614, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/main.py", line 152, in pytest_runtestloop
INTERNALERROR> item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 745, in __call__
INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 613, in execute
INTERNALERROR> return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 254, in _wrapped_call
INTERNALERROR> return call_outcome.get_result()
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 279, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 265, in __init__
INTERNALERROR> self.result = func()
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 614, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/runner.py", line 66, in pytest_runtest_protocol
INTERNALERROR> runtestprotocol(item, nextitem=nextitem)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/runner.py", line 79, in runtestprotocol
INTERNALERROR> reports.append(call_and_report(item, "call", log))
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/runner.py", line 135, in call_and_report
INTERNALERROR> report = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 745, in __call__
INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 613, in execute
INTERNALERROR> return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 250, in _wrapped_call
INTERNALERROR> wrap_controller.send(call_outcome)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/skipping.py", line 222, in pytest_runtest_makereport
INTERNALERROR> rep = outcome.get_result()
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 279, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 265, in __init__
INTERNALERROR> self.result = func()
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 614, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/runner.py", line 272, in pytest_runtest_makereport
INTERNALERROR> longrepr = item.repr_failure(excinfo)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/python.py", line 587, in repr_failure
INTERNALERROR> return self._repr_failure_py(excinfo, style=style)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/python.py", line 580, in _repr_failure_py
INTERNALERROR> style=style)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/main.py", line 433, in _repr_failure_py
INTERNALERROR> style=style, tbfilter=tbfilter)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/_code/code.py", line 423, in getrepr
INTERNALERROR> return fmt.repr_excinfo(self)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/_code/code.py", line 626, in repr_excinfo
INTERNALERROR> reprtraceback = self.repr_traceback(excinfo)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/_code/code.py", line 607, in repr_traceback
INTERNALERROR> reprentry = self.repr_traceback_entry(entry, einfo)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/_code/code.py", line 554, in repr_traceback_entry
INTERNALERROR> source = self._getentrysource(entry)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/_code/code.py", line 479, in _getentrysource
INTERNALERROR> source = entry.getsource(self.astcache)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/_code/code.py", line 205, in getsource
INTERNALERROR> astnode=astnode)
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/_pytest/_code/source.py", line 349, in getstatementrange_ast
INTERNALERROR> astnode = compile(content, "source", "exec", 1024) # 1024 for AST
INTERNALERROR> File "/Users/surana/Projects/tmp/pytesting/example.py", line 10, in raise_ex
INTERNALERROR> raise eclass()
INTERNALERROR> ArithmeticError
============================ 1 passed in 0.03 seconds ============================
Thanks for submitting an issue!
Here's a quick checklist in what to include:
We use the builtin
compilefunction to process Python code at runtime. I wrote a unit test that replacedcompilewith a function that raises many different types of exceptions. Curiously, some of those exceptions caused an INTERNALERROR in pytest. I don't know what's happening, but it appears monkeypatch is replacingcompilewhen pytest is trying to use it. This is strange, because monkeypatch shouldn't be called until the unit test executes.pip listof the virtual environment you are using$ py.test --version This is pytest version 3.0.3, imported from /Users/surana/Projects/tmp/pytesting/lib/python3.5/site-packages/pytest.py