dazzling-elephant-33766
01/31/2023, 3:56 PMlib/platform/tests/test_advice_models.py
which imports from lib.business_rules
import lib.business_rules # noqa
def test_thing():
assert 1 == 1
Running this locally, everything works completely fine ✅
$ ./pants test --force lib/platform/tests/test_advice_models.py
15:51:25.09 [INFO] Completed: Run Pytest - lib/platform/tests/test_advice_models.py - succeeded.
Partition: platform
✓ lib/platform/tests/test_advice_models.py succeeded in 0.85s.
But running the same test in CI gives an error ❌
==================================== ERRORS ====================================
__________ ERROR collecting lib/platform/tests/test_advice_models.py ___________
ImportError while importing test module '/tmp/pants-sandbox-5gjBP7/lib/platform/tests/test_advice_models.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/importlib/__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
lib/platform/tests/test_advice_models.py:1: in <module>
import lib.business_rules # noqa
E ModuleNotFoundError: No module named 'lib.business_rules'
My GH action is invoking the exact test file (the same way I would run locally)
jobs:
build_and_test_python:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
steps:
- uses: actions/checkout@v3
- uses: pantsbuild/actions/init-pants@v2
- name: Test
run: |
./pants test lib/platform/tests/test_advice_models.py
if: always() # We want the log even on failures.
Checking the output of
./pants dependencies --transitive lib/platform/tests/test_advice_models.py
Includes things in lib.business_rules
so unsure why CI is unable to find this module
lib/business_rules/__init__.py
lib/business_rules/engine.py
lib/business_rules/operators.py
It’s a long shot (apologies), but any idea how I could begin to debug what’s going on here? (I’m on pants 2.15.0rc2 )curved-television-6568
01/31/2023, 3:59 PMcurved-television-6568
01/31/2023, 3:59 PMcurved-television-6568
01/31/2023, 4:00 PMdazzling-elephant-33766
01/31/2023, 4:11 PMpants.ci.toml
I can see this in the job
Run if [ "${PANTS_CONFIG_FILES}" == "DEFAULT" ]; then
NOT setting PANTS_CONFIG_FILES by default
because pants.ci.toml does not exist.
Run ./pants --version
What’s interesting is I just noticed
16:07:06.45 [WARN] Pants cannot infer owners for the following imports in the target lib/auth/tests/test_thing.py:
* lib.business_rules (line: 1)
But I don’t see this same message when running
./pants --no-pantsd test --force --debug lib/platform/tests/test_advice_models.py
curved-television-6568
01/31/2023, 4:16 PM./pants peek
at various files and targets can help shed a light on what may be wrong..?dazzling-elephant-33766
01/31/2023, 4:23 PM$ ./pants peek lib/platform/tests/test_advice_models.py
[
{
"address": "lib/platform/tests/test_advice_models.py",
"target_type": "python_test",
"batch_compatibility_tag": "platform",
"dependencies": [
"lib/business_rules/__init__.py",
"lib/platform/__init__.py",
"lib/platform/tests/conftest.py:test_utils"
],
So I can see lib/business_rules
in here 🤔 I’ll throw the same command in CI and see what happens.enough-analyst-54434
01/31/2023, 4:34 PMbuild
file? CI Linux won't recognize those. They must be BUILD
.dazzling-elephant-33766
01/31/2023, 4:42 PM$ git status --ignored lib/business_rules
On branch pants-migration
Your branch is up to date with 'origin/pants-migration'.
Ignored files:
(use "git add -f <file>..." to include in what will be committed)
lib/business_rules/.coverage
lib/business_rules/.pytest_cache/
lib/business_rules/BUILD
lib/business_rules/tests/BUILD
It looks like I’d at some point gitignored the build files in lib/business_rules
🤦♂️
But thanks for the pointer for checking the build files!happy-kitchen-89482
01/31/2023, 5:26 PMhappy-kitchen-89482
01/31/2023, 5:27 PMdazzling-elephant-33766
01/31/2023, 5:29 PMlib/business_rules
had it’s own .gitignore
file:
*.py[cod]
# C extensions
*.so
# Packages
*.egg
*.egg-info
dist
build
Which was blocking the BUILD
files 🤦♂️curved-television-6568
01/31/2023, 6:58 PM