From 2a05c311e90a82ee547fa16fdcd77e12327eb5e0 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Wed, 20 Jul 2016 17:15:29 +0200 Subject: [PATCH 1/3] implement exitfirst as store_const option this makes it possible to override with a later maxfail --- _pytest/main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/_pytest/main.py b/_pytest/main.py index 845d5dd00..6119fcb03 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -34,8 +34,8 @@ def pytest_addoption(parser): # "**/test_*.py", "**/*_test.py"] #) group = parser.getgroup("general", "running and selection options") - group._addoption('-x', '--exitfirst', action="store_true", default=False, - dest="exitfirst", + group._addoption('-x', '--exitfirst', action="store_const", + dest="maxfail", const=1, help="exit instantly on first error or failed test."), group._addoption('--maxfail', metavar="num", action="store", type=int, dest="maxfail", default=0, @@ -74,10 +74,10 @@ def pytest_namespace(): collect = dict(Item=Item, Collector=Collector, File=File, Session=Session) return dict(collect=collect) + def pytest_configure(config): pytest.config = config # compatibiltiy - if config.option.exitfirst: - config.option.maxfail = 1 + def wrap_session(config, doit): """Skeleton command line program""" From 3fd8257c170591078ff1a8eb489ccf82de7dd8f0 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Wed, 20 Jul 2016 17:20:10 +0200 Subject: [PATCH 2/3] add test for --maxfail=NUM overiding -x --- testing/test_session.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/testing/test_session.py b/testing/test_session.py index e3b9f0fcc..a7dcb27a4 100644 --- a/testing/test_session.py +++ b/testing/test_session.py @@ -197,6 +197,14 @@ class TestNewSession(SessionTests): colfail = [x for x in finished if x.failed] assert len(colfail) == 1 + def test_minus_x_overriden_by_maxfail(self, testdir): + testdir.makepyfile(__init__="") + testdir.makepyfile(test_one="xxxx", test_two="yyyy", test_third="zzz") + reprec = testdir.inline_run("-x", "--maxfail=2", testdir.tmpdir) + finished = reprec.getreports("pytest_collectreport") + colfail = [x for x in finished if x.failed] + assert len(colfail) == 2 + def test_plugin_specify(testdir): pytest.raises(ImportError, """ From 0403266bf0e7180d31a4c394a6f207ba4affe6b0 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Wed, 20 Jul 2016 17:23:07 +0200 Subject: [PATCH 3/3] record --exitfirst change in changelog --- CHANGELOG.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f86cdce71..ec7ad5fea 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -51,6 +51,9 @@ time or change existing behaviors in order to make them less surprising/more use * ``_pytest.monkeypatch.monkeypatch`` class has been renamed to ``_pytest.monkeypatch.MonkeyPatch`` so it doesn't conflict with the ``monkeypatch`` fixture. +* ``--exitfirst / -x`` can now be overridden by a following ``--maxfail=N`` + and is just a synonym for ``--maxfail=1``. + * *