MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_pdb_suspends_fixture_capturing

Function test_pdb_suspends_fixture_capturing

testing/test_debugging.py:1190–1235  ·  view source on GitHub ↗

Using "-s" with pytest should suspend/resume fixture capturing.

(pytester: Pytester, fixture: str)

Source from the content-addressed store, hash-verified

1188
1189@pytest.mark.parametrize("fixture", ("capfd", "capsys"))
1190def test_pdb_suspends_fixture_capturing(pytester: Pytester, fixture: str) -> None:
1191 """Using "-s" with pytest should suspend/resume fixture capturing."""
1192 p1 = pytester.makepyfile(
1193 """
1194 def test_inner({fixture}):
1195 import sys
1196
1197 print("out_inner_before")
1198 sys.stderr.write("err_inner_before\\n")
1199
1200 __import__("pdb").set_trace()
1201
1202 print("out_inner_after")
1203 sys.stderr.write("err_inner_after\\n")
1204
1205 out, err = {fixture}.readouterr()
1206 assert out =="out_inner_before\\nout_inner_after\\n"
1207 assert err =="err_inner_before\\nerr_inner_after\\n"
1208 """.format(
1209 fixture=fixture
1210 )
1211 )
1212
1213 child = pytester.spawn_pytest(str(p1) + " -s")
1214
1215 child.expect("Pdb")
1216 before = child.before.decode("utf8")
1217 assert (
1218 "> PDB set_trace (IO-capturing turned off for fixture %s) >" % (fixture)
1219 in before
1220 )
1221
1222 # Test that capturing is really suspended.
1223 child.sendline("p 40 + 2")
1224 child.expect("Pdb")
1225 assert "\r\n42\r\n" in child.before.decode("utf8")
1226
1227 child.sendline("c")
1228 rest = child.read().decode("utf8")
1229 assert "out_inner" not in rest
1230 assert "err_inner" not in rest
1231
1232 TestPDB.flush(child)
1233 assert child.exitstatus == 0
1234 assert "= 1 passed in" in rest
1235 assert "> PDB continue (IO-capturing resumed for fixture %s) >" % (fixture) in rest
1236
1237
1238def test_pdbcls_via_local_module(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 5

makepyfileMethod · 0.45
formatMethod · 0.45
spawn_pytestMethod · 0.45
readMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected