calm-window-49831
07/30/2024, 8:30 PM└── src
├── python
│ ├── platform_hardware
│ │ ├── folder1
│ │ ├── folder2
│ │ ├── tests
│ │ | ├── BUILD
│ │ | ├── test_file1.py
│ │ | ├── test_file2.py
│ │ | └── mock_interface.py
│ │ ├── __main__.py
│ │ └── BUILD
Here is the BUILD file in my tests directory:
python_test_utils(
name="test_utils",
sources=["mock_interface.py"]
)
python_tests(
name="tests",
dependencies=[":test_utils"]
)
Both of my test files import from the mock_interfact.py file, and that import looks like this:
from tests.mock_interface import MockInterface
When I try to run my tests using pants test src/python/platform_hardware/tests:
I get the following error:
from tests.mock_interface import MockInterface
E ModuleNotFoundError: No module named 'tests'
I feel like there is a really simple solution here that I'm missing, but I've been pulling my hair out for hours trying to get these tests to run. I've tried using fully qualified names in the BUILD file, I've tried creating the target for this file as both a file or python source, and I've tried importing this file in all the ways that make sense to me.
What am I missing/doing wrong here?better-van-82973
07/30/2024, 8:47 PMtests
isn’t a package so I don’t think you can import from it like that. Try adding a ___init___.py
file inside the tests
directory and see if that works?calm-window-49831
07/30/2024, 9:22 PMbetter-van-82973
07/30/2024, 9:23 PMplatform_hardware
?calm-window-49831
07/30/2024, 9:23 PMbetter-van-82973
07/30/2024, 9:25 PMpants --keep_sandboxes=on_failure test src/python/platform_hardware/tests::
Since it fails, the sandbox should be retained on local disk, and you can go to that folder and see what files are inside. I’m guessing something is not being added to the sandbox where it should be.calm-window-49831
07/30/2024, 9:34 PMbetter-van-82973
07/30/2024, 9:36 PMcalm-window-49831
07/30/2024, 9:43 PMbetter-van-82973
07/30/2024, 9:45 PMfrom tests.mock_interface import MockInterface
to:
from platform_hardware.tests.mock_interface import MockInterface
calm-window-49831
07/30/2024, 9:52 PMcalm-window-49831
07/30/2024, 9:59 PMelegant-florist-94385
07/30/2024, 10:13 PMcalm-window-49831
07/30/2024, 10:41 PMcalm-window-49831
07/30/2024, 10:44 PM