dazzling-elephant-33766
01/06/2023, 12:32 PMservice/a/test/test_a.py
service/a/test/test_b.py
service/a/test/test_c.py
Will re-use the same DB.
Since pants runs each pytest in a separate process I had to create a unique DB name for each and run any initial migrations xN times. This overhead unfortunately makes the tests slower than they were before, even with parallel execution.
Is there’s any mechanism to force pytest to run tests in a single process? Passing --debug
still appears to run the DB setup/teardown once per test file. Whereas ideally I’d like it to run once for the whole suite.wide-midnight-78598
01/06/2023, 12:52 PMdazzling-elephant-33766
01/06/2023, 12:53 PMwide-midnight-78598
01/06/2023, 12:57 PMsparse-lifeguard-95737
01/06/2023, 1:20 PMhappy-kitchen-89482
01/06/2023, 2:13 PMplain-night-51324
01/09/2023, 6:55 AM./pants test ::
but each test passes when I run them individually like ./pants test file/to/tests/foo.py
Have not tried execution_slot_var yet.pytest
process”. Does that mean when I run ./pants test ::
since they run in dedicated processes they will be parallelized and result in db conflicts? So basically the best case scenario is if I set them to the same batch_compatibility_tag for all my tests, but even then it isn’t guaranteed they run in the same process tests.dazzling-elephant-33766
01/09/2023, 10:17 AMexecution_slot_var
is almost certainly what I’m looking for here. So I can run the db/init/migration setup once per service, but test each service against a different DB.
For now I’d just like to get the batching working, and worry about execution slots + different DB’s later.
I’m on 2.15.0rc1
and I’ve added the following to the BUILD
file in the same dir as my tests/conftest.py
as detailed in https://www.pantsbuild.org/v2.15/docs/python-test-goal#batching-tests
python_test_utils(
name="test_utils",
)
__defaults__({(python_test, python_tests): dict(batch_compatibility_tag="your-tag-here"),})
Are there additional steps required here? Pants still appears to be running tests in multiple processes, because half the suite is failing (as the db already exists)
psycopg2.errors.DuplicateDatabase: database "blah" already exists
I’m a bit wary of this snippet:
Compatible tests may not end up in the samebatch if:pytest
• There are “too many” tests with the same, as determined by thebatch_compatibility_tag
setting.[test].batch_size
• Compatible tests have some incompatibility in Pants metadata (i.e. differentperhaps I’m hitting some sort of batch limit, but ideally I’d like this to be unbounded.orresolve
).extra_env_vars
happy-kitchen-89482
01/09/2023, 10:44 AMpytest
process per test file, and those processes will run concurrently. If you use the test batching feature then each pytest
process will run multiple test files, but they will still run concurrently.execution_slot_var
is what lets you do that without the test colliding on database accesspytest-xdist
as the concurrency mechanism, but you'd still get no caching.dazzling-elephant-33766
01/09/2023, 11:19 AMpants.toml
in the root of my repo hasn’t changed the behaviour. I’m still seeing what appears to be separate pytest processes for each test file. I’m invoking the tests with ./pants test services/a/tests:: -- -s
and observing pytest trying to create the same test DB over and over.
[test]
batch_size = 1000
sparse-lifeguard-95737
01/09/2023, 2:39 PMdazzling-elephant-33766
01/09/2023, 2:41 PMservice/a/BUILD
instead of service/a/test/BUILD
(which is where I have my contest.py
+ test_abc.py
) files. Documentation confused me a tad. My test suite for that service is all passing now ✅