polite-angle-19513
07/06/2023, 2:18 PMpython_test_utils(
name="test_utils",
sources=[
"**/setup.py", "**/__init__.py",
],
)
python_tests(
name="tests",
dependencies=[
"src/python/api-client:lib",
":test_utils",
":test_resource",
],
sources=[
"**/*_test.py",
],
interpreter_constraints=parametrize(py38=["==3.8.*"]),
)
resource(
name="test_resource", source="resource/api_client_map_good.json"
)
The setup.py exists in the same directory as the relative_test.py script referencing the classes in setup.py. I've run with --keep-sandboxes=always to inspect the temporary sandbox. It appears that the setup.py was copied into the sandbox.
j13@guardian:/tmp/pants-sandbox-ez8dUf/test/python/api-client/lib/client/response$ ls -l
total 16
drwxrwxr-x 2 j13 j13 60 Jun 29 15:14 __pycache__
-rw-r--r-- 1 j13 j13 2334 Jun 29 15:13 relative_test.py
-rw-r--r-- 1 j13 j13 8846 Jun 29 15:13 setup.py
The relative_test.py imports setup.py as:
from setup import APIClientTestSetup
However on running pants test - the test doesn't run.
j13@guardian:~/AppDevelopment/github/hank-ai/mondo$ rm -rf /tmp/pants-sandbox-*; pants --keep-sandboxes=always test test/python/hank-ai-api-client/lib/client/response/relative_test.py -- -s
15:13:15.90 [WARN] Pants cannot infer owners for the following imports in the target test/python/hank-ai-api-client/lib/client/response/relative_test.py:../../../tests@interpreter_constraints=py38:
* setup.APIClientTestSetup (line: 30)
If you do not expect an import to be inferrable, add `# pants: no-infer-dep` to the import line. Otherwise, see <https://www.pantsbuild.org/v2.16/docs/troubleshooting#import-errors-and-missing-dependencies> for common problems.
15:13:15.94 [INFO] Preserving local process execution dir /tmp/pants-sandbox-5g3WqC for Run Pytest for test/python/hank-ai-api-client/lib/client/response/relative_test.py:../../../tests@interpreter_constraints=py38
15:13:17.00 [ERROR] Completed: Run Pytest - test/python/hank-ai-api-client/lib/client/response/relative_test.py:../../../tests@interpreter_constraints=py38 - failed (exit code 5).
============================= test session starts ==============================
collected 0 items
- generated xml file: /tmp/pants-sandbox-5g3WqC/test.python.hank-ai-api-client.lib.client.response.relative_test.py@@@tests@@interpreter_constraints=py38.xml -
============================ no tests ran in 0.69s =============================
ā test/python/hank-ai-api-client/lib/client/response/relative_test.py:../../../tests@interpreter_constraints=py38 failed in 1.04s.
Without the python_test_utils, the relative_test.py test is run but rightfully complains about the missing import.
If I comment the import line the test is still not executed.
from utils.setup import APIClientTestSetup # pants: no-infer-dep
j13@guardian:~/AppDevelopment/github/hank-ai/mondo$ rm -rf /tmp/pants-sand*; pants --keep-sandboxes=always test test/python/hank-ai-api-client/lib/client/response/relative_test.py -- -s
10:14:44.96 [INFO] Preserving local process execution dir /tmp/pants-sandbox-0BDNiM for Determine Python dependencies for test/python/hank-ai-api-client/lib/client/response/relative_test.py:../../../tests@interpreter_constraints=py38
10:14:45.20 [INFO] Preserving local process execution dir /tmp/pants-sandbox-sbIiWr for Run Pytest for test/python/hank-ai-api-client/lib/client/response/relative_test.py:../../../tests@interpreter_constraints=py38
10:14:46.27 [ERROR] Completed: Run Pytest - test/python/hank-ai-api-client/lib/client/response/relative_test.py:../../../tests@interpreter_constraints=py38 - failed (exit code 5).
============================= test session starts ==============================
collected 0 items
- generated xml file: /tmp/pants-sandbox-sbIiWr/test.python.hank-ai-api-client.lib.client.response.relative_test.py@@@tests@@interpreter_constraints=py38.xml -
============================ no tests ran in 0.69s =============================
ā test/python/hank-ai-api-client/lib/client/response/relative_test.py:../../../tests@interpreter_constraints=py38 failed in 1.05s.
Any and all insights appreciated. Thank you.high-magician-46188
07/06/2023, 2:24 PMsetup
and utils
are modules rather than packages.
Try using absolute paths. (e.g from my_package.utils.setup import APIClientTestSetup
).polite-angle-19513
07/06/2023, 2:55 PMclass APIClientTestSetup(unittest.TestCase):
Import pathing is so confounding sometimes - Here's the path in the sandbox.
(eoan)j13@guardian:/tmp/pants-sandbox-XtcypX/test/python/hank-ai-api-client/lib/client/response$ ls
__pycache__ relative_test.py setup.py
I'm presuming that the import path for APIClientTestSetup would/could be relative since it happens to be in the same directory.
Regardless I perhaps have shot myself in the foot with the intermediate 'hank-ai-api-client' containing hyphens as if I try the absolute path relative to the sandbox root when the relative_test.py is executed it is invalid syntax.
import test.python.hank-ai-api-client.lib.client.response.setup APIClientTestSetup
E from test.python.hank-ai-api-client.lib.client.response.setup import APIClientTestSetup # pants: no-infer-dep
E ^
E SyntaxError: invalid syntax
I'll rename the intermediate directory name to be underscored to see it it makes a difference.
After renaming with underscores, moving ~/.cache/pants, updating .gitignore and re-running pants is reporting in error:
!test/python/hank_ai_api_client/lib/
j13@guardian:~/AppDevelopment/github/hank-ai/mondo$ rm -rf /tmp/pants-sand*; pants --keep-sandboxes=always test test/python/hank_ai_api_client/lib/client/response/relative_test.py -- -s
10:52:01.40 [ERROR] 1 Exception encountered:
Engine traceback:
in `test` goal
IntrinsicError: Unmatched glob from CLI arguments: "test/python/hank_ai_api_client/lib/client/response/relative_test.py"
Do the file(s) exist? If so, check if the file(s) are in your `.gitignore` or the global `pants_ignore` option, which may result in Pants not being able to see the file(s) even though they exist on disk. Refer to <https://www.pantsbuild.org/v2.16/docs/troubleshooting#pants-cannot-find-a-file-in-your-project>.
high-magician-46188
07/06/2023, 2:58 PM__init__.py
will resolve it? (disclaimer: I'm not a maintainer).polite-angle-19513
07/06/2023, 3:34 PM__init__.py
all over. It at least get's past the intrinsicError but still gets an exit(5) on interpreter_contraints.high-magician-46188
07/06/2023, 5:57 PMpolite-angle-19513
07/06/2023, 6:23 PM<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite name="pytest" errors="0" failures="0" skipped="0" tests="0" time="0.764" timestamp="2023-07-06T11:30:08.366539" hostname="guardian" /></testsuites>
I'll see if any pytest exit codes might match - but unclear if it's from pants or pytest or just where. (I'll see to about increasing verbosity during pants run.)polite-angle-19513
07/06/2023, 6:35 PMbroad-processor-92400
07/06/2023, 10:02 PMpolite-angle-19513
07/07/2023, 5:53 PM