Skip to content

Commit 93aae98

Browse files
authored
Merge pull request #1744 from RonnyPfannschmidt/existfirst-override
allow --exitfirst/-x to be overridden by a following --maxfail
2 parents 1204cba + 0403266 commit 93aae98

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ time or change existing behaviors in order to make them less surprising/more use
5151
* ``_pytest.monkeypatch.monkeypatch`` class has been renamed to ``_pytest.monkeypatch.MonkeyPatch``
5252
so it doesn't conflict with the ``monkeypatch`` fixture.
5353

54+
* ``--exitfirst / -x`` can now be overridden by a following ``--maxfail=N``
55+
and is just a synonym for ``--maxfail=1``.
56+
5457
*
5558

5659
*

_pytest/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def pytest_addoption(parser):
3434
# "**/test_*.py", "**/*_test.py"]
3535
#)
3636
group = parser.getgroup("general", "running and selection options")
37-
group._addoption('-x', '--exitfirst', action="store_true", default=False,
38-
dest="exitfirst",
37+
group._addoption('-x', '--exitfirst', action="store_const",
38+
dest="maxfail", const=1,
3939
help="exit instantly on first error or failed test."),
4040
group._addoption('--maxfail', metavar="num",
4141
action="store", type=int, dest="maxfail", default=0,
@@ -74,10 +74,10 @@ def pytest_namespace():
7474
collect = dict(Item=Item, Collector=Collector, File=File, Session=Session)
7575
return dict(collect=collect)
7676

77+
7778
def pytest_configure(config):
7879
pytest.config = config # compatibiltiy
79-
if config.option.exitfirst:
80-
config.option.maxfail = 1
80+
8181

8282
def wrap_session(config, doit):
8383
"""Skeleton command line program"""

testing/test_session.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ def test_minus_x_import_error(self, testdir):
197197
colfail = [x for x in finished if x.failed]
198198
assert len(colfail) == 1
199199

200+
def test_minus_x_overriden_by_maxfail(self, testdir):
201+
testdir.makepyfile(__init__="")
202+
testdir.makepyfile(test_one="xxxx", test_two="yyyy", test_third="zzz")
203+
reprec = testdir.inline_run("-x", "--maxfail=2", testdir.tmpdir)
204+
finished = reprec.getreports("pytest_collectreport")
205+
colfail = [x for x in finished if x.failed]
206+
assert len(colfail) == 2
207+
200208

201209
def test_plugin_specify(testdir):
202210
pytest.raises(ImportError, """

0 commit comments

Comments
 (0)