Skip to content
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

Relative imports don't work with ward CLI, but do with python -m ward #3

Open
AndydeCleyre opened this issue Oct 5, 2024 · 0 comments

Comments

@AndydeCleyre
Copy link
Owner

Copying this from my comment on closed, related, upstream ward issue 152.

My test cases had been importing from adjacent modules (from commands import ...), but Pyright didn't love that, so I did the minimum to turn my test folder into a package: added __init__.py and changed relative imports to from .commands import ...). Ward doesn't like this:

ModuleNotFoundError: No module named 'test.commands'

but I noticed it works fine in CI where it's wrapped by coverage:

coverage run -p -m ward

So I checked and see it also works fine if ward is invoked as:

python -m ward

It would be great to have the plain ward invocation work here as well, unless I'm missing something wrong with that.

For reference, this project is here and the change that introduced this problem for ward is:

commit c755f39298e6063377e3debdd3061247aa461cf3
Author: Andy Kluger <[email protected]>
Date:   Tue Sep 17 14:17:13 2024 -0400

    Make test dir a package for pyright-friendly relative imports

diff --git a/test/__init__.py b/test/__init__.py
new file mode 100644
index 0000000..598d40e
--- /dev/null
+++ b/test/__init__.py
@@ -0,0 +1 @@
+"""Test suite for NestedTextTo."""
diff --git a/test/test_json.py b/test/test_json.py
index 6ae29ea..2f3f3dd 100644
--- a/test/test_json.py
+++ b/test/test_json.py
@@ -2,11 +2,12 @@
 
 from typing import cast
 
-from commands import json2nt, nt2json
 from plumbum import LocalPath, local
-from utils import assert_file_content, casting_args_from_schema_file
 from ward import test
 
+from .commands import json2nt, nt2json
+from .utils import assert_file_content, casting_args_from_schema_file
+
 SAMPLES = local.path(__file__).up() / 'samples' / 'json'  # type: ignore
 
 
diff --git a/test/test_toml.py b/test/test_toml.py
index 66ab146..aef6551 100644
--- a/test/test_toml.py
+++ b/test/test_toml.py
@@ -2,11 +2,12 @@
 
 from typing import cast
 
-from commands import nt2toml, toml2nt
 from plumbum import LocalPath, local
-from utils import assert_file_content, casting_args_from_schema_file
 from ward import skip, test
 
+from .commands import nt2toml, toml2nt
+from .utils import assert_file_content, casting_args_from_schema_file
+
 try:
     import tomli  # noqa: F401
     import tomli_w  # noqa: F401
diff --git a/test/test_yaml.py b/test/test_yaml.py
index 773e44a..1e64f12 100644
--- a/test/test_yaml.py
+++ b/test/test_yaml.py
@@ -2,11 +2,12 @@
 
 from typing import cast
 
-from commands import nt2yaml, yaml2nt
 from plumbum import LocalPath, local
-from utils import assert_file_content, casting_args_from_schema_file
 from ward import test
 
+from .commands import nt2yaml, yaml2nt
+from .utils import assert_file_content, casting_args_from_schema_file
+
 SAMPLES = local.path(__file__).up() / 'samples' / 'yaml'  # type: ignore
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

No branches or pull requests

1 participant