Skip to content

Commit f153ad3

Browse files
authored
pytester: use no colors with inline runs by default (#58)
Sets `PY_COLORS=0` in the environment by default, which is used by pylib.
1 parent 5d2a995 commit f153ad3

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/_pytest/pytester.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,11 @@ def __init__(self, request, tmpdir_factory):
496496

497497
# Environment (updates) for inner runs.
498498
tmphome = str(self.tmpdir)
499-
self._env_run_update = {"HOME": tmphome, "USERPROFILE": tmphome}
499+
self._env_run_update = {
500+
"HOME": tmphome,
501+
"USERPROFILE": tmphome,
502+
"PY_COLORS": "0",
503+
}
500504

501505
def __repr__(self):
502506
return "<Testdir {!r}>".format(self.tmpdir)

testing/test_pdb.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def test_not_called_due_to_quit():
257257
child.sendeof()
258258
rest = child.read().decode("utf8")
259259
assert "Exit: Quitting debugger" in rest
260-
assert "= \x1b[31m\x1b[1m1 failed\x1b[0m\x1b[31m in" in rest
260+
assert "= 1 failed in" in rest
261261
assert "def test_1" not in rest
262262
assert "get rekt" not in rest
263263
self.flush(child)
@@ -542,7 +542,7 @@ def function_1():
542542
rest = child.read().decode("utf8")
543543

544544
assert "! _pytest.outcomes.Exit: Quitting debugger !" in rest
545-
assert "= \x1b[33mno tests ran\x1b[0m\x1b[33m in" in rest
545+
assert "= no tests ran in" in rest
546546
assert "BdbQuit" not in rest
547547
assert "UNEXPECTED EXCEPTION" not in rest
548548

@@ -761,7 +761,7 @@ def do_continue(self, arg):
761761
assert "> PDB continue (IO-capturing resumed) >" in rest
762762
else:
763763
assert "> PDB continue >" in rest
764-
assert "= \x1b[32m\x1b[1m1 passed\x1b[0m\x1b[32m in" in rest
764+
assert "= 1 passed in" in rest
765765

766766
def test_pdb_used_outside_test(self, testdir):
767767
p1 = testdir.makepyfile(
@@ -1081,7 +1081,7 @@ def test_3():
10811081
child.sendline("q")
10821082
child.expect_exact("Exit: Quitting debugger")
10831083
rest = child.read().decode("utf8")
1084-
assert "= \x1b[32m\x1b[1m2 passed\x1b[0m\x1b[32m in" in rest
1084+
assert "= 2 passed in" in rest
10851085
assert "reading from stdin while output" not in rest
10861086
# Only printed once - not on stderr.
10871087
assert "Exit: Quitting debugger" not in child.before.decode("utf8")
@@ -1126,7 +1126,7 @@ def test_func_kw(myparam, request, func="func_kw"):
11261126
child.sendline("c")
11271127
child.expect_exact("> PDB continue (IO-capturing resumed) >")
11281128
rest = child.read().decode("utf8")
1129-
assert "= \x1b[32m\x1b[1m6 passed\x1b[0m\x1b[32m in" in rest
1129+
assert "= 6 passed in" in rest
11301130
assert "reading from stdin while output" not in rest
11311131
# Only printed once - not on stderr.
11321132
assert "Exit: Quitting debugger" not in child.before.decode("utf8")
@@ -1237,7 +1237,7 @@ def test_inner({fixture}):
12371237

12381238
TestPDB.flush(child)
12391239
assert child.exitstatus == 0
1240-
assert "= \x1b[32m\x1b[1m1 passed\x1b[0m\x1b[32m in" in rest
1240+
assert "= 1 passed in" in rest
12411241
assert "> PDB continue (IO-capturing resumed for fixture %s) >" % (fixture) in rest
12421242

12431243

@@ -1376,9 +1376,7 @@ def target():
13761376
child.expect("target_start")
13771377
child.expect(r"\(Pdb")
13781378
child.sendline("evt2.set()")
1379-
child.expect_exact(
1380-
"= \x1b[32m\x1b[1m1 passed\x1b[0m\x1b[32m in"
1381-
) # main thread exited
1379+
child.expect_exact("= 1 passed in") # main thread exited
13821380
child.sendline("c")
13831381
child.expect(r"\(Pdb")
13841382
child.sendline("c")

testing/test_terminal.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ def test_1():
158158
"test2.py": "def test_2(): pass",
159159
}
160160
)
161+
# Explicitly test colored output.
162+
testdir._env_run_update["PY_COLORS"] = "1"
161163

162164
child = testdir.spawn_pytest("-v test1.py test2.py")
163165
child.expect(r"collecting \.\.\.")

0 commit comments

Comments
 (0)