userver: /data/code/service_template/third_party/userver/testsuite/pytest_plugins/pytest_userver/plugins/base.py Source File
Loading...
Searching...
No Matches
base.py
1"""
2Configure the service in testsuite.
3"""
4
5import pathlib
6
7import pytest
8
9
10def pytest_addoption(parser) -> None:
11 group = parser.getgroup('userver')
12 group.addoption(
13 '--build-dir',
14 type=pathlib.Path,
15 help='Path to service build directory.',
16 )
17
18 group = parser.getgroup('Test service')
19 group.addoption(
20 '--service-binary', type=pathlib.Path, help='Path to service binary.',
21 )
22 group.addoption(
23 '--service-port',
24 help='Bind example services to this port (default is %(default)s)',
25 default=8080,
26 type=int,
27 )
28 group.addoption(
29 '--monitor-port',
30 help='Bind example monitor to this port (default is %(default)s)',
31 default=8086,
32 type=int,
33 )
34 group.addoption(
35 '--service-source-dir',
36 type=pathlib.Path,
37 help='Path to service source directory.',
38 default=pathlib.Path('.'),
39 )
40
41
42@pytest.fixture(scope='session')
43def service_source_dir(pytestconfig) -> pathlib.Path:
44 """
45 Returns the path to the service source directory that is set by command
46 line `--service-source-dir` option.
47
48 Override this fixture to change the way the path to the service
49 source directory is detected by testsuite.
50
51 @ingroup userver_testsuite_fixtures
52 """
53 return pytestconfig.option.service_source_dir
54
55
56@pytest.fixture(scope='session')
57def build_dir(pytestconfig) -> pathlib.Path:
58 """
59 Returns the build directory set by command line `--build-dir` option.
60
61 Override this fixture to change the way the build directory is
62 detected by the testsuite.
63
64 @ingroup userver_testsuite_fixtures
65 """
66 return pytestconfig.option.build_dir
67
68
69@pytest.fixture(scope='session')
70def service_binary(pytestconfig) -> pathlib.Path:
71 """
72 Returns the path to service binary set by command line `--service-binary`
73 option.
74
75 Override this fixture to change the way the path to service binary is
76 detected by the testsuite.
77
78 @ingroup userver_testsuite_fixtures
79 """
80 return pytestconfig.option.service_binary
81
82
83@pytest.fixture(scope='session')
84def service_port(pytestconfig) -> int:
85 """
86 Returns the main listener port number of the service set by command line
87 `--service-port` option.
88
89 Override this fixture to change the way the main listener port number is
90 detected by the testsuite.
91
92 @ingroup userver_testsuite_fixtures
93 """
94 return pytestconfig.option.service_port
95
96
97@pytest.fixture(scope='session')
98def monitor_port(pytestconfig) -> int:
99 """
100 Returns the monitor listener port number of the service set by command line
101 `--monitor-port` option.
102
103 Override this fixture to change the way the monitor listener port number
104 is detected by testsuite.
105
106 @ingroup userver_testsuite_fixtures
107 """
108 return pytestconfig.option.monitor_port