-
Notifications
You must be signed in to change notification settings - Fork 54
ModuleNotFoundError/ImportError within ward #152
Comments
Hi Jason, thanks for the report. I think if you call ward with It's running into some issues as it's finding some modules inside your virtualenv prefixed with For example, ward finds I haven't had time to implement it yet, but #81 should hopefully resolve most cases of this issue. I will also make another issue to not fail the full test run, and instead print a warning when something like this is encountered. The |
Alternatively, set the path in pyproject.toml as I've been doing.
I hate this practice so much ^_^
I find this to be a bit problematic. For example, in ward, you put the test suite inside your package directory and then exclude them from being packaged. That doesn't really seem right. Right now, I work around this by adding an Pytest does some magic to allow most of this, but not sure that's something you'd want to do. |
Yeah, most of this should be fine for adapting, but the lack of relative path support is going to be problematic long term. We should definitely fix that. |
For reference, here are the docs for the way pytest works with sys.path/PYTHONPATH. |
As of 0.44.0b0, Ward no longer looks in site-packages when discovering tests. I'll keep this issue open as I believe there may still be issues if you use relative imports in your own project. |
Interestingly, pytest 6 has an option to use I've tested this out in pytest and ward, and in both cases relative imports cause errors regardless of whether the relative There are some other issues being reported with A PR open in pytest discussing possible solutions that may come in handy in the future: pytest-dev/pytest#7936 |
Relative imports should be fixed in 0.53.0b0, which is now on PyPI |
My test cases had been importing from adjacent modules (
but I noticed it works fine in CI where it's wrapped by 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 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 |
I have
ward
installed in a virtual environment on Python 3.7.5, and I'm getting the following error when executing theward
command in the root of my repository. My code lives in a packageomission
directly in this repository, and that package contains subpackages and submodules configured as tests.Here are the versions of the packages installed in my virtual environment:
Here's the error I'm encountering:
After installing
ddt
manually (ddt-1.3.1
), I get this error instead when runningward
:Interestingly, if I install
pytest
as well, the error onward
changes yet again:For the record, installing
pytest
as well installs the following:The text was updated successfully, but these errors were encountered: