It should be imported in pytest_configure or later only.
(pytester: Pytester)
| 1236 | |
| 1237 | |
| 1238 | def 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 | |
| 1281 | def test_raises_bdbquit_with_eoferror(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected