Skip to content

Commit a1219ab

Browse files
committed
pytester: use no colors with inline runs by default
Sets `PY_COLORS=0` in the environment by default, which is used by pylib. Via blueyed#58 (initially cherry picked from commit f153ad3)
1 parent 47ae1fb commit a1219ab

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/_pytest/pytester.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,12 @@ def __init__(self, request, tmpdir_factory):
544544
mp.delenv("TOX_ENV_DIR", raising=False)
545545
# Discard outer pytest options.
546546
mp.delenv("PYTEST_ADDOPTS", raising=False)
547-
548-
# Environment (updates) for inner runs.
547+
# Ensure no user config is used.
549548
tmphome = str(self.tmpdir)
550549
mp.setenv("HOME", tmphome)
551550
mp.setenv("USERPROFILE", tmphome)
551+
# Do not use colors for inner runs by default.
552+
mp.setenv("PY_COLORS", "0")
552553

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

testing/test_pdb.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def test_one(self):
193193
)
194194
child = testdir.spawn_pytest("-rs --pdb %s" % p1)
195195
child.expect("Skipping also with pdb active")
196-
child.expect_exact("= \x1b[33m\x1b[1m1 skipped\x1b[0m\x1b[33m in")
196+
child.expect_exact("= 1 skipped in")
197197
child.sendeof()
198198
self.flush(child)
199199

@@ -221,7 +221,7 @@ def test_not_called_due_to_quit():
221221
child.sendeof()
222222
rest = child.read().decode("utf8")
223223
assert "Exit: Quitting debugger" in rest
224-
assert "= \x1b[31m\x1b[1m1 failed\x1b[0m\x1b[31m in" in rest
224+
assert "= 1 failed in" in rest
225225
assert "def test_1" not in rest
226226
assert "get rekt" not in rest
227227
self.flush(child)
@@ -506,7 +506,7 @@ def function_1():
506506
rest = child.read().decode("utf8")
507507

508508
assert "! _pytest.outcomes.Exit: Quitting debugger !" in rest
509-
assert "= \x1b[33mno tests ran\x1b[0m\x1b[33m in" in rest
509+
assert "= no tests ran in" in rest
510510
assert "BdbQuit" not in rest
511511
assert "UNEXPECTED EXCEPTION" not in rest
512512

@@ -725,7 +725,7 @@ def do_continue(self, arg):
725725
assert "> PDB continue (IO-capturing resumed) >" in rest
726726
else:
727727
assert "> PDB continue >" in rest
728-
assert "= \x1b[32m\x1b[1m1 passed\x1b[0m\x1b[32m in" in rest
728+
assert "= 1 passed in" in rest
729729

730730
def test_pdb_used_outside_test(self, testdir):
731731
p1 = testdir.makepyfile(
@@ -1041,7 +1041,7 @@ def test_3():
10411041
child.sendline("q")
10421042
child.expect_exact("Exit: Quitting debugger")
10431043
rest = child.read().decode("utf8")
1044-
assert "= \x1b[32m\x1b[1m2 passed\x1b[0m\x1b[32m in" in rest
1044+
assert "= 2 passed in" in rest
10451045
assert "reading from stdin while output" not in rest
10461046
# Only printed once - not on stderr.
10471047
assert "Exit: Quitting debugger" not in child.before.decode("utf8")
@@ -1086,7 +1086,7 @@ def test_func_kw(myparam, request, func="func_kw"):
10861086
child.sendline("c")
10871087
child.expect_exact("> PDB continue (IO-capturing resumed) >")
10881088
rest = child.read().decode("utf8")
1089-
assert "= \x1b[32m\x1b[1m6 passed\x1b[0m\x1b[32m in" in rest
1089+
assert "= 6 passed in" in rest
10901090
assert "reading from stdin while output" not in rest
10911091
# Only printed once - not on stderr.
10921092
assert "Exit: Quitting debugger" not in child.before.decode("utf8")
@@ -1197,7 +1197,7 @@ def test_inner({fixture}):
11971197

11981198
TestPDB.flush(child)
11991199
assert child.exitstatus == 0
1200-
assert "= \x1b[32m\x1b[1m1 passed\x1b[0m\x1b[32m in" in rest
1200+
assert "= 1 passed in" in rest
12011201
assert "> PDB continue (IO-capturing resumed for fixture %s) >" % (fixture) in rest
12021202

12031203

testing/test_terminal.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ def test_1():
154154
"test2.py": "def test_2(): pass",
155155
}
156156
)
157+
# Explicitly test colored output.
158+
testdir.monkeypatch.setenv("PY_COLORS", "1")
157159

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

0 commit comments

Comments
 (0)