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(
'.'),
48@pytest.fixture(scope='session')
51 Returns the path to the service source directory that is set by command
52 line `--service-source-dir` option.
54 Override this fixture to change the way the path to the service
55 source directory is detected by testsuite.
57 @ingroup userver_testsuite_fixtures
59 return pytestconfig.option.service_source_dir
62@pytest.fixture(scope='session')
65 Returns the build directory set by command line `--build-dir` option.
67 Override this fixture to change the way the build directory is
68 detected by the testsuite.
70 @ingroup userver_testsuite_fixtures
72 return pytestconfig.option.build_dir
75@pytest.fixture(scope='session')
78 Returns the path to service binary set by command line `--service-binary`
81 Override this fixture to change the way the path to service binary is
82 detected by the testsuite.
84 @ingroup userver_testsuite_fixtures
86 return pytestconfig.option.service_binary
89@pytest.fixture(scope='session')
92 Returns the main listener port number of the service set by command line
93 `--service-port` option.
94 If no port is specified in the command line option, keeps the original port
95 specified in the static config.
97 Override this fixture to change the way the main listener port number is
98 detected by the testsuite.
100 @ingroup userver_testsuite_fixtures
102 return pytestconfig.option.service_port
or _get_port(
103 _original_service_config,
'listener', service_port,
'--service-port',
107@pytest.fixture(scope='session')
110 Returns the monitor listener port number of the service set by command line
111 `--monitor-port` option.
112 If no port is specified in the command line option, keeps the original port
113 specified in the static config.
115 Override this fixture to change the way the monitor listener port number
116 is detected by testsuite.
118 @ingroup userver_testsuite_fixtures
120 return pytestconfig.option.monitor_port
or _get_port(
121 _original_service_config,
129 original_service_config, listener_name, port_fixture, option_name,
131 config_yaml = original_service_config.config_yaml
132 config_vars = original_service_config.config_vars
133 components = config_yaml[
'components_manager'][
'components']
134 listener = components.get(
'server', {}).get(listener_name, {})
137 port = listener.get(
'port',
None)
138 if isinstance(port, str)
and port.startswith(
'$'):
139 port = config_vars.get(port[1:],
None)
or listener.get(
140 'port#fallback',
None,
144 f
'components_manager.components.server.{listener_name}.port '
145 f
'in the static config, or pass {option_name} pytest option, '
146 f
'or override the {port_fixture.__name__} fixture'