How do you execute unit-tests that require third-p...
# general
r
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
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
No, that's about the state of it. We don't have explicit support for launching long lived daemons.
r
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
@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
@happy-kitchen-89482 just opened this one
🙏 1