| 274 | # =========================================================================== |
| 275 | |
| 276 | class TestDynamicImport: |
| 277 | def test_import_in_tests_not_flagged(self): |
| 278 | """__import__() used in test discovery should not be flagged.""" |
| 279 | code = """ |
| 280 | backend_pkg = __import__(package) |
| 281 | test_module = __import__(test_module_name, {}, {}, test_path[-1]) |
| 282 | """ |
| 283 | assert findings_for_rule(code, "IMPORT825", in_tests_dir=True) == [], \ |
| 284 | "IMPORT825 should not fire in test files" |
| 285 | |
| 286 | def test_import_in_production_flagged(self): |
| 287 | """__import__() in production code should still be flagged.""" |
| 288 | code = """ |
| 289 | module = __import__(user_provided_module_name) |
| 290 | """ |
| 291 | assert findings_for_rule(code, "IMPORT825", in_tests_dir=False) != [], \ |
| 292 | "IMPORT825 should still fire in production code" |
| 293 | |
| 294 | |
| 295 | # =========================================================================== |
nothing calls this directly
no outgoing calls
no test coverage detected