Skip to content

pytester: use no colors with inline runs by default #6164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/_pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,12 @@ def __init__(self, request, tmpdir_factory):
mp.delenv("TOX_ENV_DIR", raising=False)
# Discard outer pytest options.
mp.delenv("PYTEST_ADDOPTS", raising=False)

# Environment (updates) for inner runs.
# Ensure no user config is used.
tmphome = str(self.tmpdir)
mp.setenv("HOME", tmphome)
mp.setenv("USERPROFILE", tmphome)
# Do not use colors for inner runs by default.
mp.setenv("PY_COLORS", "0")

def __repr__(self):
return "<Testdir {!r}>".format(self.tmpdir)
Expand Down
14 changes: 7 additions & 7 deletions testing/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def test_one(self):
)
child = testdir.spawn_pytest("-rs --pdb %s" % p1)
child.expect("Skipping also with pdb active")
child.expect_exact("= \x1b[33m\x1b[1m1 skipped\x1b[0m\x1b[33m in")
child.expect_exact("= 1 skipped in")
child.sendeof()
self.flush(child)

Expand Down Expand Up @@ -221,7 +221,7 @@ def test_not_called_due_to_quit():
child.sendeof()
rest = child.read().decode("utf8")
assert "Exit: Quitting debugger" in rest
assert "= \x1b[31m\x1b[1m1 failed\x1b[0m\x1b[31m in" in rest
assert "= 1 failed in" in rest
assert "def test_1" not in rest
assert "get rekt" not in rest
self.flush(child)
Expand Down Expand Up @@ -506,7 +506,7 @@ def function_1():
rest = child.read().decode("utf8")

assert "! _pytest.outcomes.Exit: Quitting debugger !" in rest
assert "= \x1b[33mno tests ran\x1b[0m\x1b[33m in" in rest
assert "= no tests ran in" in rest
assert "BdbQuit" not in rest
assert "UNEXPECTED EXCEPTION" not in rest

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

def test_pdb_used_outside_test(self, testdir):
p1 = testdir.makepyfile(
Expand Down Expand Up @@ -1041,7 +1041,7 @@ def test_3():
child.sendline("q")
child.expect_exact("Exit: Quitting debugger")
rest = child.read().decode("utf8")
assert "= \x1b[32m\x1b[1m2 passed\x1b[0m\x1b[32m in" in rest
assert "= 2 passed in" in rest
assert "reading from stdin while output" not in rest
# Only printed once - not on stderr.
assert "Exit: Quitting debugger" not in child.before.decode("utf8")
Expand Down Expand Up @@ -1086,7 +1086,7 @@ def test_func_kw(myparam, request, func="func_kw"):
child.sendline("c")
child.expect_exact("> PDB continue (IO-capturing resumed) >")
rest = child.read().decode("utf8")
assert "= \x1b[32m\x1b[1m6 passed\x1b[0m\x1b[32m in" in rest
assert "= 6 passed in" in rest
assert "reading from stdin while output" not in rest
# Only printed once - not on stderr.
assert "Exit: Quitting debugger" not in child.before.decode("utf8")
Expand Down Expand Up @@ -1197,7 +1197,7 @@ def test_inner({fixture}):

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


Expand Down
2 changes: 2 additions & 0 deletions testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ def test_1():
"test2.py": "def test_2(): pass",
}
)
# Explicitly test colored output.
testdir.monkeypatch.setenv("PY_COLORS", "1")

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