Skip to content

Commit 45ed4c7

Browse files
Merged in hpk42/pytest-patches/plug30 (pull request #291)
use new pluggy api (now at 0.3.0) for adding hookcall monitoring
2 parents b93abfb + d9a4409 commit 45ed4c7

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

_pytest/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#
2-
__version__ = '2.8.0.dev3'
2+
__version__ = '2.8.0.dev4'

_pytest/pytester.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import py
1414
import pytest
1515
from py.builtin import print_
16-
from pluggy import _TracedHookExecution
1716

1817
from _pytest.main import Session, EXIT_OK
1918

@@ -194,12 +193,13 @@ def __init__(self, pluginmanager):
194193
self._pluginmanager = pluginmanager
195194
self.calls = []
196195

197-
def before(hook, method, kwargs):
198-
self.calls.append(ParsedCall(hook.name, kwargs))
199-
def after(outcome, hook, method, kwargs):
196+
def before(hook_name, hook_impls, kwargs):
197+
self.calls.append(ParsedCall(hook_name, kwargs))
198+
199+
def after(outcome, hook_name, hook_impls, kwargs):
200200
pass
201-
executor = _TracedHookExecution(pluginmanager, before, after)
202-
self._undo_wrapping = executor.undo
201+
202+
self._undo_wrapping = pluginmanager.add_hookcall_monitoring(before, after)
203203

204204
def finish_recording(self):
205205
self._undo_wrapping()
@@ -667,6 +667,7 @@ def inline_run(self, *args, **kwargs):
667667
class Collect:
668668
def pytest_configure(x, config):
669669
rec.append(self.make_hook_recorder(config.pluginmanager))
670+
670671
plugins = kwargs.get("plugins") or []
671672
plugins.append(Collect())
672673
ret = pytest.main(list(args), plugins=plugins)
@@ -677,6 +678,13 @@ def pytest_configure(x, config):
677678
class reprec:
678679
pass
679680
reprec.ret = ret
681+
682+
# typically we reraise keyboard interrupts from the child run
683+
# because it's our user requesting interruption of the testing
684+
if ret == 2 and not kwargs.get("no_reraise_ctrlc"):
685+
calls = reprec.getcalls("pytest_keyboard_interrupt")
686+
if calls and calls[-1].excinfo.type == KeyboardInterrupt:
687+
raise KeyboardInterrupt()
680688
return reprec
681689

682690
def runpytest_inprocess(self, *args, **kwargs):
@@ -688,7 +696,7 @@ def runpytest_inprocess(self, *args, **kwargs):
688696
capture = py.io.StdCapture()
689697
try:
690698
try:
691-
reprec = self.inline_run(*args)
699+
reprec = self.inline_run(*args, **kwargs)
692700
except SystemExit as e:
693701
class reprec:
694702
ret = e.args[0]

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def has_environment_marker_support():
4848

4949

5050
def main():
51-
install_requires = ['py>=1.4.27.dev2', 'pluggy>=0.2.0,<0.3.0']
51+
install_requires = ['py>=1.4.27.dev2', 'pluggy>=0.3.0,<0.4.0']
5252
extras_require = {}
5353
if has_environment_marker_support():
5454
extras_require[':python_version=="2.6" or python_version=="3.0" or python_version=="3.1"'] = ['argparse']

testing/test_terminal.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,16 @@ class TestMore(BaseTests):
132132
])
133133

134134
def test_itemreport_directclasses_not_shown_as_subclasses(self, testdir):
135-
a = testdir.mkpydir("a")
136-
a.join("test_hello.py").write(py.code.Source("""
135+
a = testdir.mkpydir("a123")
136+
a.join("test_hello123.py").write(py.code.Source("""
137137
class TestClass:
138138
def test_method(self):
139139
pass
140140
"""))
141141
result = testdir.runpytest("-v")
142142
assert result.ret == 0
143143
result.stdout.fnmatch_lines([
144-
"*a/test_hello.py*PASS*",
144+
"*a123/test_hello123.py*PASS*",
145145
])
146146
assert " <- " not in result.stdout.str()
147147

@@ -155,7 +155,7 @@ def test_interrupt_me():
155155
raise KeyboardInterrupt # simulating the user
156156
""")
157157

158-
result = testdir.runpytest(*option.args)
158+
result = testdir.runpytest(*option.args, no_reraise_ctrlc=True)
159159
result.stdout.fnmatch_lines([
160160
" def test_foobar():",
161161
"> assert 0",
@@ -178,7 +178,7 @@ def test_foobar():
178178
pass
179179
""")
180180

181-
result = testdir.runpytest()
181+
result = testdir.runpytest(no_reraise_ctrlc=True)
182182
assert result.ret == 2
183183
result.stdout.fnmatch_lines(['*KeyboardInterrupt*'])
184184

0 commit comments

Comments
 (0)