summaryrefslogtreecommitdiff
path: root/testing/test_pytester.py
diff options
context:
space:
mode:
authorBruno Oliveira <nicoddemus@gmail.com>2019-10-22 19:33:54 -0300
committerBruno Oliveira <bruno@esss.com.br>2019-10-23 09:16:02 -0300
commit7beb520555b7908c647c5cfa35bbfc3e48b28638 (patch)
treef4bdb2715ce8fec0083de4c89987eec545c95faf /testing/test_pytester.py
parent978c7ae1b72e410be6d2db25cee2817e91c2d4e4 (diff)
downloadpytest-7beb520555b7908c647c5cfa35bbfc3e48b28638.tar.gz
Show the mnemonic of pytest.ExitCode in RunResult's repr
Fix #4901
Diffstat (limited to 'testing/test_pytester.py')
-rw-r--r--testing/test_pytester.py30
1 files changed, 19 insertions, 11 deletions
diff --git a/testing/test_pytester.py b/testing/test_pytester.py
index f8b0896c5..1a068c1d0 100644
--- a/testing/test_pytester.py
+++ b/testing/test_pytester.py
@@ -121,17 +121,6 @@ def test_runresult_assertion_on_xpassed(testdir):
assert result.ret == 0
-def test_runresult_repr():
- from _pytest.pytester import RunResult
-
- assert (
- repr(
- RunResult(ret="ret", outlines=[""], errlines=["some", "errors"], duration=1)
- )
- == "<RunResult ret='ret' len(stdout.lines)=1 len(stderr.lines)=2 duration=1.00s>"
- )
-
-
def test_xpassed_with_strict_is_considered_a_failure(testdir):
testdir.makepyfile(
"""
@@ -616,3 +605,22 @@ def test_spawn_uses_tmphome(testdir):
child = testdir.spawn_pytest(str(p1))
out = child.read()
assert child.wait() == 0, out.decode("utf8")
+
+
+def test_run_result_repr():
+ outlines = ["some", "normal", "output"]
+ errlines = ["some", "nasty", "errors", "happened"]
+
+ # known exit code
+ r = pytester.RunResult(1, outlines, errlines, duration=0.5)
+ assert (
+ repr(r) == "<RunResult ret=ExitCode.TESTS_FAILED len(stdout.lines)=3"
+ " len(stderr.lines)=4 duration=0.50s>"
+ )
+
+ # unknown exit code: just the number
+ r = pytester.RunResult(99, outlines, errlines, duration=0.5)
+ assert (
+ repr(r) == "<RunResult ret=99 len(stdout.lines)=3"
+ " len(stderr.lines)=4 duration=0.50s>"
+ )