2Configure the service in testsuite.
15def pytest_addoption(parser) -> None:
16 group = parser.getgroup(
'userver')
20 help=
'Path to service build directory.',
23 group = parser.getgroup(
'Test service')
25 '--service-binary', type=pathlib.Path, help=
'Path to service binary.',
30 'Main HTTP port of the service '
31 '(default: use the port from the static config)'
39 'Monitor HTTP port of the service '
40 '(default: use the port from the static config)'
46 '--service-source-dir',
48 help=
'Path to service source directory.',
49 default=pathlib.Path(
'.'),
53@pytest.hookimpl(hookwrapper=True, tryfirst=True)
54def pytest_runtest_makereport(item, call):
55 if not hasattr(item,
'utestsuite_report'):
58 rep = outcome.get_result()
60 item.utestsuite_report.failed =
True
64@pytest.fixture(scope='session')
67 Returns the path to the service source directory that is set by command
68 line `--service-source-dir` option.
70 Override this fixture to change the way the path to the service
71 source directory is detected by testsuite.
73 @ingroup userver_testsuite_fixtures
75 return pytestconfig.option.service_source_dir
78@pytest.fixture(scope='session')
81 Returns the build directory set by command line `--build-dir` option.
83 Override this fixture to change the way the build directory is
84 detected by the testsuite.
86 @ingroup userver_testsuite_fixtures
88 return pytestconfig.option.build_dir
91@pytest.fixture(scope='session')
94 Returns the path to service binary set by command line `--service-binary`
97 Override this fixture to change the way the path to service binary is
98 detected by the testsuite.
100 @ingroup userver_testsuite_fixtures
102 return pytestconfig.option.service_binary
105@pytest.fixture(scope='session')
108 Returns the main listener port number of the service set by command line
109 `--service-port` option.
110 If no port is specified in the command line option, keeps the original port
111 specified in the static config.
113 Override this fixture to change the way the main listener port number is
114 detected by the testsuite.
116 @ingroup userver_testsuite_fixtures
118 return pytestconfig.option.service_port
or _get_port(
119 _original_service_config,
'listener', service_port,
'--service-port',
123@pytest.fixture(scope='session')
126 Returns the monitor listener port number of the service set by command line
127 `--monitor-port` option.
128 If no port is specified in the command line option, keeps the original port
129 specified in the static config.
131 Override this fixture to change the way the monitor listener port number
132 is detected by testsuite.
134 @ingroup userver_testsuite_fixtures
136 return pytestconfig.option.monitor_port
or _get_port(
137 _original_service_config,
145 original_service_config, listener_name, port_fixture, option_name,
147 config_yaml = original_service_config.config_yaml
148 config_vars = original_service_config.config_vars
149 components = config_yaml[
'components_manager'][
'components']
150 listener = components.get(
'server', {}).get(listener_name, {})
153 port = listener.get(
'port',
None)
154 if isinstance(port, str)
and port.startswith(
'$'):
155 port = config_vars.get(port[1:],
None)
or listener.get(
156 'port#fallback',
None,
160 f
'components_manager.components.server.{listener_name}.port '
161 f
'in the static config, or pass {option_name} pytest option, '
162 f
'or override the {port_fixture.__name__} fixture'