Skip to content

Add test coverage for sys.modules fallback path in get_scope#188

Merged
samwaseda merged 4 commits intosamwaseda-patch-1from
copilot/sub-pr-186
Mar 18, 2026
Merged

Add test coverage for sys.modules fallback path in get_scope#188
samwaseda merged 4 commits intosamwaseda-patch-1from
copilot/sub-pr-186

Conversation

Copy link
Contributor

Copilot AI commented Mar 18, 2026

Summary

get_scope's fallback branch (module = sys.modules.get(module_name), line 53) was unreachable by existing tests because inspect.getmodule internally calls sys.modules.get(object.__module__) — meaning if the module is in sys.modules, it never returns None and the fallback is skipped entirely. This PR adds test coverage for that path and fixes repository hygiene by removing a generated file from version control.

Related Issue(s)

Backward Compatibility

No change to production code — test-only addition.

Implementation Notes

  • tests/unit/models/parsers/test_object_scope.py

    • Added test_sys_modules_fallback_when_getmodule_returns_none: patches inspect.getmodule to return None (simulating C-extension types or other objects where module resolution fails), then verifies the fallback correctly resolves the module via sys.modules.get(module_name) and returns a valid ScopeProxy
    • Added from unittest.mock import patch import
  • Removed accidentally committed flowrep/_version.py (a setuptools-scm generated file that explicitly states "don't track in version control") and added */_version.py to .gitignore to prevent recurrence.

The fallback path exists for objects (e.g. C-extension callables) where inspect.getmodule may fail even though a valid __module__ attribute is present. Mocking is the only reliable way to exercise this path in isolation, since naturally the two sys.modules lookups would always agree.


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Co-authored-by: samwaseda <37879103+samwaseda@users.noreply.github.com>
Copilot AI changed the title [WIP] Change get_scope parameter type from FunctionType to object Add test coverage for sys.modules fallback path in get_scope Mar 18, 2026
Copilot AI requested a review from samwaseda March 18, 2026 14:59
@samwaseda
Copy link
Member

@copilot run black

@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.97%. Comparing base (62fa0e4) to head (bcffb5c).
⚠️ Report is 5 commits behind head on samwaseda-patch-1.

Additional details and impacted files
@@                  Coverage Diff                  @@
##           samwaseda-patch-1     #188      +/-   ##
=====================================================
+ Coverage              97.92%   97.97%   +0.04%     
=====================================================
  Files                     34       34              
  Lines                   2268     2268              
=====================================================
+ Hits                    2221     2222       +1     
+ Misses                    47       46       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor Author

Copilot AI commented Mar 18, 2026

@copilot run black

Both changed files are already black-formatted — no changes needed.

@samwaseda
Copy link
Member

@copilot Remove _version.py

Co-authored-by: samwaseda <37879103+samwaseda@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 18, 2026

@copilot Remove _version.py

Done in 0c38bda — deleted flowrep/_version.py and added */_version.py to .gitignore to prevent it being committed again.

@samwaseda samwaseda marked this pull request as ready for review March 18, 2026 15:23
@samwaseda samwaseda merged commit 092f66c into samwaseda-patch-1 Mar 18, 2026
19 checks passed
@samwaseda samwaseda deleted the copilot/sub-pr-186 branch March 18, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants