good morning everybody. I'll continue today to mak...
# general
f
good morning everybody. I'll continue today to make pantsbuild happen 🙂 sadly it's a propreritary code base and I can't just show things in a repo, so I've created this structure which is hopefully similar enough regarding the setup to reason about things
Copy code
.
├── service_a
│   ├── app_a
│   │   └── tests
│   │       └── test_a.py
│   ├── app_b
│   │   └── tests
│   │       └── test_b.py
│   ├── app_c
│   │   └── tests
│   │       └── test_c.py
│   ├── manage.py
│   ├── requirements.txt
│   └── service_a
│       └── settings.py
├── service_b
│   ├── app_a
│   │   └── tests
│   │       └── test_a.py
│   ├── app_b
│   │   └── tests
│   │       └── test_b.py
│   ├── app_c
│   │   └── tests
│   │       └── test_c.py
│   ├── manage.py
│   ├── requirements.txt
│   └── service_b
│       └── settings.py
└── util
    └── settings_for_tests.py
https://app.warp.dev/block/NorDRW8zy6JkoCo1Z8VmE7 the difference to the django example is: 1. multiple apps pro service 2. tests in a submodule now I struggle to provide enough meta data to pants to make tests work, with all different kind of approaches. I'm more than willing to also create a little example repo out of this - is anyone willing to help and or interested in joining forces?
a
When you say tests in a submodule do you mean a git-module or that the tests are located in a folder below app_a, app_b etc? What kind of errors are you getting. The structure looks like it should work fine to me.
f
yeah, I'm actually currently building an example repo like this, doesn't really make sense to discuss things without actual issues I hit 🙂
ok, now I have the issue with the following repository: https://github.com/elmcrest/example-django-multiple-monoliths-pantsbuild
Copy code
pants test edmmp/service_a/app_a/tests/test_views.py
11:21:47.31 [INFO] Initializing scheduler...
11:21:49.94 [INFO] Scheduler initialized.
11:21:49.98 [WARN] Pants cannot infer owners for the following imports in the target edmmp/service_a/conftest.py:test_utils:

  * edmmp.util.settings_for_tests.configure_settings (line: 4)

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.17/docs/troubleshooting#import-errors-and-missing-dependencies> for common problems.
11:21:51.59 [WARN] Failed to generate JUnit XML data for edmmp/service_a/app_a/tests/test_views.py.
11:21:51.59 [ERROR] Completed: Run Pytest - edmmp/service_a/app_a/tests/test_views.py - failed (exit code 4).
ImportError while loading conftest '/private/var/folders/ll/98hnvg_n5l3by0224q_qybc40000gn/T/pants-sandbox-RLtdW4/edmmp/service_a/conftest.py'.
edmmp/service_a/conftest.py:4: in <module>
    from edmmp.util.settings_for_tests import configure_settings
E   ModuleNotFoundError: No module named 'edmmp'



✕ edmmp/service_a/app_a/tests/test_views.py failed in 0.32s.
so it's about
no module named 'edmmp'
which is the equivalent to
helloworld
in the django example repository.
which behaves the same if I transform
edmmp
to a python module (with adding a
___init___.py
file) and changing to
root_patterns=['*']
in pants.toml
I'm now realizing, that the official django-example has a different architecture - the django apps (
greet
and
person
) are outside of the actual django instances then, which are in
service
which might explain the import statements and the source root 🤔
a
You should use
pants dependencies
on the test file in question to see what dependencies pants has inferred automatically. I suspect the source code is not being pulled in because your tests have no explicit dependencies on the routes you're calling. In the BUILD file next to the tests:
Copy code
python_tests(dependencies=["/path/to/file/with/api_endpoint_logic.py"])
I've never used Django with Pants so I don't know if they have an integration to automatically determine which routes are used based on Regex, but I suspect they don't. As a result you need to tell pants which fil e
response = self.client.get("/app_a/")
will ultimately call.
f
there is some django specific stuff happen in pytest with the pytest-django plugin as well as with loading the django settings via conftest.py acting as a hook… Trying now to get pytest to load pytest-django via resolves (but first lunch)
it seems I still can't get my head around that:
Copy code
pants dependencies --transitive edmmp/service_a/app_a/test_views.py
3rdparty/python/edmmp-lock.txt:_edmmp_lockfile
edmmp/service_a/conftest.py:test_utils
edmmp/service_a/requirements.txt:reqs
edmmp/service_a:reqs#django
edmmp/util/settings_for_tests.py
and
Copy code
pants test edmmp/service_a/app_a/test_views.py
13:21:01.83 [INFO] Completed: Building pytest.pex
13:21:01.84 [ERROR] 1 Exception encountered:

Engine traceback:
  in `test` goal

ProcessExecutionFailure: Process 'Building pytest.pex' failed with exit code 1.
stdout:

stderr:
Could not find script 'pytest' in any distribution  within PEX!



Use `--keep-sandboxes=on_failure` to preserve the process chroot for inspection.
I also pushed most recent changes to the repo just in case
ok that above is different kind of things, ignore please... going back to the module not found
r
If you are trying to use import statement as
Copy code
from edmmp import ..
Your source root should have.
Copy code
root_patterns = ["/"]
f
yeah ok, I got a bit closer I guess ... now running into an issue where django can't find the referenced 'urls' module in the provided test settings
it seems i got it working!!!!! 🎉
yeeeeeees!!!
🔥 3