https://pantsbuild.org/ logo
#general
Title
# general
r

rough-electrician-21871

07/28/2022, 8:32 AM
How do you execute unit-tests that require third-party applications? We have a monorepo with go and python microservices and some tests of some services do need a PostgreSQL instance and/or other service(s) to be run before the execution. With classic CI/CD approach we just define these dependencies (db, other services) in
docker-compose
file, where required, and run
docker-compose up
prior to executing
pytest
, for example. So the layout of monorepo looks roughly like this:
Copy code
└── services
  ├── go-service-1
  │  └── <CODEBASE>
  │  └── docker-compose.yaml
  ├── py-service-1
  │  └── <CODEBASE>
  │  └── docker-compose.yaml
  └── py-service-2
  │  └── <CODEBASE>
    └── docker-compose.yaml
But I don’t see a clear way for
pants
to understand that it need to execute
docker-compose up
in a directory
path/to/service/foo
upon a code-change of that service foo And the use-case is quite common, so perhaps it’s solved somehow differently? Maybe I need to employ
experimental_shell_command
to spin up DBs and set some envs for unit tests to consume? Basically, that’s the only stopping factor of us starting to adopt
pants
— i simply don’t understand how to solve my issue at hand..
👀 2
h

happy-kitchen-89482

07/28/2022, 4:41 PM
We don't have very strong support for this sort of thing yet, to be honest. One way could be to depend on an
experimental_shell_command
(although that doesn't give you teardown at the end). Another is to lean on
conftest.py
, but because that runs for every test file (Pants invokes pytest on each test file separately, for better concurrency and caching) that may not work for setting up global state without a lot of complication.
@witty-crayon-22786 am I missing something here? we really should add more explicit support for global setup/teardown
w

witty-crayon-22786

07/28/2022, 4:50 PM
No, that's about the state of it. We don't have explicit support for launching long lived daemons.
r

rough-electrician-21871

07/29/2022, 8:42 AM
Another is to lean on
conftest.py
but it doesn’t resolve the case for non-python codebases, and the solution begs to be language-agnostic, I’d say Do you think
pants
should handle it or rather rely on some tooling instead?
It could be possibly resolved with a
pre-hook
and
post-hook
thing. This would allow to cover many use cases with a relatively generalised approach, I gather
h

happy-kitchen-89482

07/29/2022, 11:19 PM
@rough-electrician-21871 could you open a ticket for this at https://github.com/pantsbuild/pants/issues ? I agree that Pants should solve this
r

rough-electrician-21871

08/01/2022, 1:40 PM
@happy-kitchen-89482 just opened this one
🙏 1
7 Views