-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix discovery of modules in namespace packages #228
Changes from 4 commits
8a58ef1
682c688
9d6ae69
8626cc2
908f6d4
9f60d08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,19 @@ def test_module_doesnt_exist(runner: CliRunner): | |
) | ||
|
||
|
||
def test_python_file_not_in_sys_path(runner: CliRunner, tmpdir): | ||
file = tmpdir / "foo.py" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like It returns There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't know about this! Excellent! love |
||
file.write_text('print("Hello, world!")', encoding="utf-8") | ||
result = runner.invoke(cli, [str(file)]) | ||
assert result.exit_code == 1 | ||
assert isinstance(result.exception, SystemExit) | ||
assert result.output == ( | ||
"ERROR: Module 'foo' not found.\n\n" | ||
"See slotscheck.rtfd.io/en/latest/discovery.html\n" | ||
"for help resolving common import problems.\n" | ||
) | ||
|
||
|
||
def test_module_is_uninspectable(runner: CliRunner): | ||
result = runner.invoke(cli, ["-m", "broken.submodule"]) | ||
assert result.exit_code == 1 | ||
|
@@ -157,6 +170,16 @@ def test_multiple_modules(runner: CliRunner): | |
assert result.output == "All OK!\nScanned 11 module(s), 70 class(es).\n" | ||
|
||
|
||
def test_implicitly_namespaced_path(runner: CliRunner): | ||
result = runner.invoke( | ||
cli, | ||
[str(EXAMPLES_DIR / "implicitly_namespaced")], | ||
catch_exceptions=False, | ||
) | ||
assert result.exit_code == 0 | ||
assert result.output == "All OK!\nScanned 7 module(s), 1 class(es).\n" | ||
|
||
|
||
def test_multiple_paths(runner: CliRunner): | ||
result = runner.invoke( | ||
cli, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that you want to reuse the logic in cli.py, but this error can be very misleading.
ModuleNotFoundError
means we could not resolve a "dotted.module.name". Here we could not find a module name for a file path. We were going in the opposite direction (file -> module instead of module -> file), which does not normally happen in Python. I suggest that we add a new exception type for this, keep the full file path, and handle it in cli.py similar to ModuleNotFoundError.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, let's do a custom exception 👍