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

Function test_pdbcls_via_local_module

testing/test_debugging.py:1238–1278  ·  view source on GitHub ↗

It should be imported in pytest_configure or later only.

(pytester: Pytester)

Source from the content-addressed store, hash-verified

1236
1237
1238def test_pdbcls_via_local_module(pytester: Pytester) -> None:
1239 """It should be imported in pytest_configure or later only."""
1240 p1 = pytester.makepyfile(
1241 """
1242 def test():
1243 print("before_set_trace")
1244 __import__("pdb").set_trace()
1245 """,
1246 mypdb="""
1247 class Wrapped:
1248 class MyPdb:
1249 def set_trace(self, *args):
1250 print("set_trace_called", args)
1251
1252 def runcall(self, *args, **kwds):
1253 print("runcall_called", args, kwds)
1254 """,
1255 )
1256 result = pytester.runpytest(
1257 str(p1), "--pdbcls=really.invalid:Value", syspathinsert=True
1258 )
1259 result.stdout.fnmatch_lines(
1260 [
1261 "*= FAILURES =*",
1262 "E * --pdbcls: could not import 'really.invalid:Value': No module named *really*",
1263 ]
1264 )
1265 assert result.ret == 1
1266
1267 result = pytester.runpytest(
1268 str(p1), "--pdbcls=mypdb:Wrapped.MyPdb", syspathinsert=True
1269 )
1270 assert result.ret == 0
1271 result.stdout.fnmatch_lines(["*set_trace_called*", "* 1 passed in *"])
1272
1273 # Ensure that it also works with --trace.
1274 result = pytester.runpytest(
1275 str(p1), "--pdbcls=mypdb:Wrapped.MyPdb", "--trace", syspathinsert=True
1276 )
1277 assert result.ret == 0
1278 result.stdout.fnmatch_lines(["*runcall_called*", "* 1 passed in *"])
1279
1280
1281def test_raises_bdbquit_with_eoferror(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 3

fnmatch_linesMethod · 0.80
makepyfileMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected