File: test_1000x.py

package info (click to toggle)
python-syrupy 4.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,368 kB
  • sloc: python: 5,978; makefile: 3
file content (38 lines) | stat: -rw-r--r-- 1,020 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# type: ignore
import shutil
from pathlib import Path


def test_1000x_reads(testdir, benchmark):
    test_contents = """
        import pytest

        @pytest.mark.parametrize("x", range(1000))
        def test_performance(x, snapshot):
            assert x == snapshot
        """
    testdir.makepyfile(test=test_contents)

    # This test benchmarks reads not writes, so we'll pre-write the snapshots.
    testdir.runpytest("test.py", "--snapshot-update")

    # Run benchmark
    benchmark(lambda: testdir.runpytest("test.py"))


def test_1000x_writes(testdir, benchmark):
    test_contents = """
        import pytest

        @pytest.mark.parametrize("x", range(1000))
        def test_performance(x, snapshot):
            assert x == snapshot
        """

    def fn():
        test_path = testdir.makepyfile(test=test_contents)
        testdir.runpytest("test.py", "--snapshot-update")
        shutil.rmtree(Path(test_path).parent / "__snapshots__", ignore_errors=True)

    # Run benchmark
    benchmark(fn)