2Plugin that imports the required fixtures for checking SQL/YQL coverage. See
3@ref sql_coverage_test_info "SQL coverage tests" for more info.
5@ingroup userver_testsuite_fixtures
8from collections.abc
import Iterable
9from collections.abc
import Sequence
15pytest_plugins = [
'pytest_userver.plugins.generated_tests']
21 Called when the coverage is incomplete.
23 Override this fixture to change the way uncovered statements are reported or to ignore some of the statements
26 See @ref sql_coverage_test_info "SQL coverage tests" for more info.
28 @ingroup userver_testsuite_fixtures
31 def _on_uncovered(uncovered_statements: set[str]):
32 msg = f
'Uncovered SQL/YQL statements: {uncovered_statements}'
40 Contains data about the current coverage of statements.
43 def __init__(self, files: set[str]):
48 def cover(self, statement: str) ->
None:
55 def validate(self, uncovered_callback: callable) ->
None:
60@pytest.fixture(scope='session')
61def sql_coverage(sql_files) -> Coverage:
63 Returns data about the current coverage of statements.
65 See @ref sql_coverage_test_info "SQL coverage tests" for more info.
67 @ingroup userver_testsuite_fixtures
72@pytest.fixture(autouse=True)
75 Hook that accepts requests from the testpoint with information on PostgreSQL statements coverage.
77 See @ref sql_coverage_test_info "SQL coverage tests" for more info.
79 @ingroup userver_testsuite_fixtures
82 @testpoint('sql_statement')
84 sql_coverage.cover(request[
'name'])
89@pytest.fixture(autouse=True)
92 Hook that accepts requests from the testpoint with information on YDB statements coverage.
94 See @ref sql_coverage_test_info "SQL coverage tests" for more info.
96 @ingroup userver_testsuite_fixtures
99 @testpoint('yql_statement')
101 sql_coverage.cover(request[
'name'])
106def test_sql_coverage(sql_coverage, on_uncovered):
107 sql_coverage.validate(on_uncovered)
110def pytest_generate_virtual_tests(
112 config: pytest.Config,
113 existing_items: Sequence[pytest.Item],
114) -> Iterable[pytest.Item]:
115 if config.pluginmanager.hasplugin(
'sql_files'):
116 yield pytest.Function.from_parent(
118 name=test_sql_coverage.__name__,
119 callobj=test_sql_coverage,
123@pytest.hookimpl(wrapper=True)
124def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item]) ->
None: