New issue 598: Ability to randomize testing order
https://bitbucket.org/hpk42/pytest/issue/598/ability-to-randomize-testing-order
liori:
I have two types of tests: CPU-bound and IO-bound. When playing with `xdist` I
realized that these tests tend to cluster, ie. there's a huge block of
CPU-bound tests, then a block of IO-bound tests, etc. I assumed that if I could
interleave these blocks of tests, the test suite will execute faster.
So I hacked up `pytest` to hardcode a simple randomization scheme; I changed
`pytest.main.Session.perform_collect` to have the following code:
```
#!python
def perform_collect(self, args=None, genitems=True):
hook = self.config.hook
try:
items = self._perform_collect(args, genitems)
hook.pytest_collection_modifyitems(session=self,
config=self.config, items=items)
finally:
import random
random.Random(42).shuffle(self.items)
hook.pytest_collection_finish(session=self)
return items
```
Before this change my test suite executed with `py.test -n 4` took 60 seconds
to complete. Now it's about 40 seconds, which means I saved ~1/3 of the time.
I hope this proves that such an option would be useful.
_______________________________________________
pytest-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-commit