2Configure the service in testsuite.
10def pytest_addoption(parser) -> None:
11 group = parser.getgroup(
'userver')
15 help=
'Path to service build directory.',
18 group = parser.getgroup(
'Test service')
20 '--service-binary', type=pathlib.Path, help=
'Path to service binary.',
25 'Main HTTP port of the service '
26 '(default: use the port from the static config)'
34 'Monitor HTTP port of the service '
35 '(default: use the port from the static config)'
41 '--service-source-dir',
43 help=
'Path to service source directory.',
44 default=pathlib.Path(
'.'),
48def pytest_configure(config):
49 config.option.asyncio_mode =
'auto'
52@pytest.fixture(scope='session')
55 Returns the path to the service source directory that is set by command
56 line `--service-source-dir` option.
58 Override this fixture to change the way the path to the service
59 source directory is detected by testsuite.
61 @ingroup userver_testsuite_fixtures
63 return pytestconfig.option.service_source_dir
66@pytest.fixture(scope='session')
69 Returns the build directory set by command line `--build-dir` option.
71 Override this fixture to change the way the build directory is
72 detected by the testsuite.
74 @ingroup userver_testsuite_fixtures
76 return pytestconfig.option.build_dir
79@pytest.fixture(scope='session')
82 Returns the path to service binary set by command line `--service-binary`
85 Override this fixture to change the way the path to service binary is
86 detected by the testsuite.
88 @ingroup userver_testsuite_fixtures
90 return pytestconfig.option.service_binary
93@pytest.fixture(scope='session')
96 Returns the main listener port number of the service set by command line
97 `--service-port` option.
98 If no port is specified in the command line option, keeps the original port
99 specified in the static config.
101 Override this fixture to change the way the main listener port number is
102 detected by the testsuite.
104 @ingroup userver_testsuite_fixtures
106 return pytestconfig.option.service_port
or _get_port(
107 _original_service_config,
'listener', service_port,
'--service-port',
111@pytest.fixture(scope='session')
114 Returns the monitor listener port number of the service set by command line
115 `--monitor-port` option.
116 If no port is specified in the command line option, keeps the original port
117 specified in the static config.
119 Override this fixture to change the way the monitor listener port number
120 is detected by testsuite.
122 @ingroup userver_testsuite_fixtures
124 return pytestconfig.option.monitor_port
or _get_port(
125 _original_service_config,
133 original_service_config, listener_name, port_fixture, option_name,
135 config_yaml = original_service_config.config_yaml
136 config_vars = original_service_config.config_vars
137 components = config_yaml[
'components_manager'][
'components']
138 listener = components.get(
'server', {}).get(listener_name, {})
141 port = listener.get(
'port',
None)
142 if isinstance(port, str)
and port.startswith(
'$'):
143 port = config_vars.get(port[1:],
None)
or listener.get(
144 'port#fallback',
None,
148 f
'components_manager.components.server.{listener_name}.port '
149 f
'in the static config, or pass {option_name} pytest option, '
150 f
'or override the {port_fixture.__name__} fixture'