File: test_benchmark_bulk_create.py

package info (click to toggle)
ormar 0.20.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,136 kB
  • sloc: python: 23,758; makefile: 34; sh: 14
file content (26 lines) | stat: -rw-r--r-- 675 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
import random
import string

import pytest

from benchmarks.conftest import Author

pytestmark = pytest.mark.asyncio


@pytest.mark.parametrize("num_models", [10, 20, 40])
async def test_making_and_inserting_models_in_bulk(aio_benchmark, num_models: int):
    @aio_benchmark
    async def make_and_insert(num_models: int):
        authors = [
            Author(
                name="".join(random.sample(string.ascii_letters, 5)),
                score=int(random.random() * 100),
            )
            for i in range(0, num_models)
        ]
        assert len(authors) == num_models

        await Author.objects.bulk_create(authors)

    make_and_insert(num_models)