Textualize / pytest-textual-snapshot

Snapshot testing for Textual applications
MIT License
21 stars 4 forks source link

Add support for pytest-xdist for **much faster** Textual tests. #9

Closed paul-ollis closed 2 months ago

paul-ollis commented 11 months ago

Attention grabbing bit

On my PC, which has 16 (real) cores.

Time to run the Textual suite of 2107 tests.

Without pytest-xdist:               2 mins, 59 seconds.
Using pytest-xdist with 8 workers:          22 seconds
Using pytest-xdist with 16 workers:         13 seconds

Details

The following changes have been made.

In order to make use of pytest-xdist for the Textual tests you must:

  1. Use the --dist=loadgroup option when executing pytest.

  2. Add pytest-xdist group decorators to the slug tests.

    @pytest.mark.xdist_group(name="group1")
    def test_simple_slug(text: str, expected: str) -> None:
    
    ...
    
    @pytest.mark.xdist_group(name="group2")
    def test_tracked_slugs(tracker: TrackedSlugs, text: str, expected: str) -> None:

    The slug tests depend on execution order and state that changes for each test. So each parameterized set of tests must run within the same pytest-xdist worker process.

paul-ollis commented 10 months ago

Please hold off merging this for now.

I have identified an improvement that I wish to add.

paul-ollis commented 10 months ago

Updates made. Once again ready for review and potential merging.

willmcgugan commented 2 months ago

@paul-ollis Sorry for the slow response on this. Going to have a chat with @darrenburns shortly. We're very excited about faster snapshots!

paul-ollis commented 2 months ago

@willmcgugan No worries. I have not actively made use of this for some months, but seem to recall that when I was, I may have found some tweaks/corner cases that cropped up during heavy use. I will revisit the project in question and get back to you with any possibly useful updates or a definitive 'no changes required'.

I hope you find it as useful as me.