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

red-account-49986

03/16/2022, 9:58 AM
Hi, I have a question regarding running pytests with pants test: I noticed when I run the tests with
./pants test foo/tests::
, pants apparently runs pytest individually on every test file inside that folder. I guess this is to allow parallel test execution. However, then the output also looks like running pytest individually, e.g. I have one pytest summary printed to terminal per test file and one pytest html report generated per test file if I use the pytest-html plugin. I would rather prefer it to behave like pytest is being run on all files at once, even if I lose parallel execution. I have found a screenshot of an older version of v2 here https://github.com/pantsbuild/pants/pull/9594 where the output looks exactly like I expect it (one test summary for multiple files), but I'm not sure if/how I can achieve that in the current pants version?
c

curved-television-6568

03/16/2022, 10:33 AM
Hi, It seems that it is not currently possible, from what I can see. (it might be possible by adding dependencies between test files… but that would be more of a hackish way of going about it) There’s an ongoing discussion regarding the trade-offs how to best partition jobs (this for lint/check I think, but could apply to some extent to test as well).
b

bitter-ability-32190

03/16/2022, 10:44 AM
I'm on mobile so it's hard to find links, but you could look into how the html plugin works and see if it takes in the xml report to generate the html one. Pants isn't unique in running tests in parallel, I know pytest-xdist does something similar. So it might be possible to find a script or some code to merge the xml reports and then generate the html from that.
c

curved-television-6568

03/16/2022, 10:48 AM
That’s good advice, Joshua. I diged up this link: https://github.com/pytest-dev/pytest-html/issues/183#issuecomment-738195470
🙌 1
h

happy-kitchen-89482

03/16/2022, 3:01 PM
Hi, you're correct that Pants runs pytest once per file, both for parallel execution and so that each test execution can be cached separately, for better cache hit rates.
👍 1
By default Pants doesn't show pytest output for tests that pass, so is the issue that you have many failures? Or are you running with
--test-output=all
?
We do now support running linters on batches of files instead of once per file, and have discussed extending this to pytest runs. Once we support that, you would be able to set the batch size to be "all the files".
r

red-account-49986

03/16/2022, 5:49 PM
Thanks, I was indeed running with a test-output=all setting in the pants.toml I forgot about 🙂 Without this, the terminal output is much cleaner. Regardless, I think it'd be great to have the option to run it on all files and have the output accordingly. The pants test summary contains all important information, but I somehow just got so used to the pytest output and its customization options 🙂
h

happy-kitchen-89482

03/17/2022, 4:20 AM
Good feedback! Would you mind opening a ticket for this request at https://github.com/pantsbuild/pants/issues/new/choose ?
If I understand correctly, what you actually care about is the output being unified, not the running on all files?
r

red-account-49986

03/17/2022, 7:57 AM
Yes, for me it doesn't matter how the tests are executed by pants. For me it's just that I'm coming from a non-pants setup where I could run pytest and customize the test summary/report using pytest options/plugins. Here, pants feels like a step back because I get a more basic summary that I cannot customize and I would have to invest effort to merge per-test-file reports (html, json) into a single report.
h

happy-kitchen-89482

03/17/2022, 11:45 PM
Great, so a ticket with that detail would be really helpful
BTW you can pass options to pytest and use pytest plugins
but it'll still apply file-by-file
6 Views