Skip to content

Commit

Permalink
Do not save data with _pytest.outcomes.Exit (#119)
Browse files Browse the repository at this point in the history
* Do not save data with _pytest.outcomes.Exit

This was changed in pytest (will be in 4.1).

`Exit` is derived from `SystemExit` and not `KeyboardInterrupt` anymore.

Ref pytest-dev/pytest#4292

* tests: use py36-pytest41-xdist
  • Loading branch information
blueyed authored and tarpas committed Jan 21, 2019
1 parent 5ce358a commit aa4d3ef
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -24,7 +24,7 @@ matrix:
python: 3.6
- env: TOXENV=py36-pytestfeatures
python: 3.6
- env: TOXENV=py36-pytest32-xdist
- env: TOXENV=py36-pytest41-xdist
python: 3.6

install:
Expand Down
28 changes: 26 additions & 2 deletions test/test_testmon.py
Expand Up @@ -301,6 +301,30 @@ def test_2():
# interrupted run shouldn't save .testmondata
assert 1800000000 == os.path.getmtime(datafilename)

def test_outcomes_exit(self, testdir):
testdir.makepyfile(test_a="""
def test_1():
1
def test_2():
2
""")
testdir.runpytest("--testmon")

tf = testdir.makepyfile(test_a="""
def test_1():
import pytest
pytest.exit("pytest_exit")
def test_2():
3
""")
os.utime(datafilename, (1800000000, 1800000000))
tf.setmtime(1800000000)
testdir.runpytest("--testmon", )
# interrupted run shouldn't save .testmondata
assert 1800000000 == os.path.getmtime(datafilename)

def test_nonfunc_class(self, testdir, monkeypatch):
""""
"""
Expand Down Expand Up @@ -788,14 +812,14 @@ class TestXdist(object):

def test_xdist_4(self, testdir):
pytest.importorskip("xdist")
testdir.makepyfile(test_a="""\
testdir.makepyfile(test_a="""
import pytest
@pytest.mark.parametrize("a", [
("test0", ),
("test1", ),
("test2", ),
("test3", )
])
])
def test_1(a):
print(a)
""")
Expand Down
3 changes: 2 additions & 1 deletion testmon/pytest_testmon.py
Expand Up @@ -215,7 +215,8 @@ def pytest_runtest_protocol(self, item, nextitem):
else:
self.testmon.start()
result = yield
if result.excinfo and issubclass(result.excinfo[0], KeyboardInterrupt):
if result.excinfo and issubclass(result.excinfo[0], (
KeyboardInterrupt, SystemExit)):
self.testmon.stop()
else:
self.testmon.stop_and_save(self.testmon_data, item.config.rootdir.strpath, item.nodeid,
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
@@ -1,5 +1,5 @@
[tox]
envlist = pytest{31,32,33,master}-py{27,34,35,36},py36-pytest32-xdist,pytestfeatures-py36
envlist = pytest{31,32,33,master}-py{27,34,35,36},py36-pytest41-xdist,pytestfeatures-py36

[testenv]
passenv = PYTHONPATH
Expand All @@ -11,6 +11,7 @@ deps =
pytest31: pytest>=3.1,<3.2
pytest32: pytest>=3.2,<3.3
pytest33: pytest>=3.3,<3.4
pytest41: pytest>=4.1,<4.2
# master is current stable version with bugfixes.
pytestmaster: git+https://github.com/pytest-dev/pytest.git@master#egg=pytest
# features is the next non-bugfix version.
Expand Down

0 comments on commit aa4d3ef

Please sign in to comment.