Coverage for tests/conftest.py: 100%
32 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
1from __future__ import annotations
3import os
4import sys
5from typing import TYPE_CHECKING, List, Iterator
7import pytest
9import prisma
10from prisma import Prisma
11from prisma.cli import setup_logging
12from lib.testing.shared_conftest import *
13from lib.testing.shared_conftest.async_client import *
15from .utils import Runner, Testdir
17if TYPE_CHECKING:
18 from _pytest.config import Config
19 from _pytest.pytester import Pytester
20 from _pytest.monkeypatch import MonkeyPatch
23LOGGING_CONTEXT_MANAGER = setup_logging(use_handler=False)
26prisma.register(Prisma())
28pytest.register_assert_rewrite('tests.test_generation.utils')
31@pytest.fixture()
32def runner(monkeypatch: 'MonkeyPatch') -> Runner:
33 """Fixture for running cli tests"""
34 return Runner(patcher=monkeypatch)
37@pytest.fixture(name='testdir')
38def testdir_fixture(pytester: Pytester) -> Iterator[Testdir]:
39 cwd = os.getcwd()
40 os.chdir(pytester.path)
41 sys.path.insert(0, str(pytester.path))
43 yield Testdir(pytester)
45 os.chdir(cwd)
46 sys.path.remove(str(pytester.path))
49# TODO: don't emulate the with statement
50def pytest_sessionstart(session: pytest.Session) -> None:
51 LOGGING_CONTEXT_MANAGER.__enter__()
54def pytest_sessionfinish(session: pytest.Session) -> None:
55 if ( # pragma: no branch
56 LOGGING_CONTEXT_MANAGER is not None
57 ): # pyright: ignore[reportUnnecessaryComparison]
58 LOGGING_CONTEXT_MANAGER.__exit__(None, None, None)
61def pytest_collection_modifyitems(session: pytest.Session, config: Config, items: List[pytest.Item]) -> None:
62 items.sort(key=lambda item: item.__class__.__name__ == 'IntegrationTestItem')