| 22 | @pytest.mark.parametrize("scenario", ["exclude_by_name", "exclude_by_dir"]) |
| 23 | @pytest.mark.parametrize("exc_type", ["RuntimeError", "SystemExit"]) |
| 24 | def test_exceptions_and_exclude_rules(pyfile, target, run, scenario, exc_type): |
| 25 | if exc_type == "RuntimeError": |
| 26 | |
| 27 | @pyfile |
| 28 | def code_to_debug(): |
| 29 | import debuggee |
| 30 | |
| 31 | debuggee.setup() |
| 32 | raise RuntimeError("unhandled error") # @raise_line |
| 33 | |
| 34 | elif exc_type == "SystemExit": |
| 35 | |
| 36 | @pyfile |
| 37 | def code_to_debug(): |
| 38 | import debuggee |
| 39 | import sys |
| 40 | |
| 41 | debuggee.setup() |
| 42 | sys.exit(1) # @raise_line |
| 43 | |
| 44 | else: |
| 45 | pytest.fail(exc_type) |
| 46 | |
| 47 | if scenario == "exclude_by_name": |
| 48 | rules = [{"path": "**/" + code_to_debug.basename, "include": False}] |
| 49 | elif scenario == "exclude_by_dir": |
| 50 | rules = [{"path": code_to_debug.dirname, "include": False}] |
| 51 | else: |
| 52 | pytest.fail(scenario) |
| 53 | log.info("Rules: {0}", json.repr(rules)) |
| 54 | |
| 55 | with debug.Session() as session: |
| 56 | session.expected_exit_code = some.int |
| 57 | session.config["rules"] = rules |
| 58 | |
| 59 | with run(session, target(code_to_debug)): |
| 60 | session.request( |
| 61 | "setExceptionBreakpoints", {"filters": ["raised", "uncaught"]} |
| 62 | ) |
| 63 | |
| 64 | # No exceptions should be seen. |
| 65 | session.wait_for_next_event("terminated") |
| 66 | session.proceed() |
| 67 | |
| 68 | |
| 69 | @pytest.mark.parametrize("scenario", ["exclude_code_to_debug", "exclude_callback_dir"]) |