how do you customize pytest test execution order? ...
# general
p
how do you customize pytest test execution order? say I want to first run unit tests and then integration tests, is it possible with single pants test command? I want to avoid rebuilding pytest executor by using multipe commands for test groups
t
Just spitballing here, but I believe you can chunk it up with multiple pytest targets. Then set your unit tests as a dependency for your integ tests.
In theory, it should run your unit tests first before integration tests, the
pants test ::
command should fail if either fails, and integration should only run if unit tests pass.
p
I see, it's should be following the execution graph, will try, thx
h
I don't think that will work, alas. The
test
goal won't execute tests in dependency order.
t
Unfortunate
h
I'll see if I can think of a way to do this
out of curiosity, what is the reason for wanting to do this?
t
Not sure. Personally, I would use tags to run integration tests and alias the command. So I run unit tests with
pants test ::
and integ tests only in CI/CD with
pants test integ
b
I want to avoid rebuilding pytest executor by using multipe commands for test groups
Presumably this is an indirect way of saying Pants / Pex are slow (bolding mine) and @purple-hydrogen-4740 is trying to hack around slow pytest PEX builds, which I think show up in Pants log output still; so would attract natural attention when you are starting to investigate slow tests.
IOW, I would guess this current hack track: https://www.pantsbuild.org/stable/reference/subsystems/python#run_against_entire_lockfile and / or the promise of a "new backend".
p
@brief-scientist-13682 that's right, my testing pipeline was split into 4 groups of tests because some tests using docker and temporal were failing due to docker/temporal interferring between each other and I could figure it out at first, it took around hour to test packages + 3 services & build docker images for the services, I have managed to set it up with claude now, so far split it into 2 pants commands using batching tags and dependencies
ah ok, I just noticed that specifying tests in dependencies doesnt maintain the execution order, that's a shame, that would be such a natural feature like for example turborepo provides
💯 1