3import cavoke_openapi_client
7def pytest_addoption(parser: pytest.Parser):
8 parser.addoption(
"--endpoint", action=
"store", default=
"http://localhost:8080", help=
"API endpoint "
10 "usually your localhost")
11 parser.addoption(
"--servercmd", action=
"store", default=
None, help=
"command to start the server process")
14def pytest_configure(config: pytest.Config):
16 Allows plugins and conftest files to perform initial configuration.
17 This hook
is called
for every plugin
and initial conftest
18 file after command line options have been parsed.
20 host = config.getoption("endpoint")
21 print(f
"Using this endpoint for testing: '{host}'", flush=
True)
22 print(f
"Please make sure that the server is NOT using JWT Auth!!!", flush=
True)
23 pytest.server_config = cavoke_openapi_client.Configuration(host=host)
26def pytest_sessionstart(session: pytest.Session):
28 Called after the Session object has been created and
29 before performing collection
and entering the run test loop.
31 server_cmd = session.config.getoption("servercmd")
32 if server_cmd
is None:
33 print(
"No process started!!!", flush=
True)
35 print(f
"Starting server process with '{server_cmd}'...", flush=
True)
36 pytest.server_process = subprocess.Popen(args=server_cmd, shell=
True)
39def pytest_sessionfinish(session, exitstatus):
41 Called after whole test run finished, right before
42 returning the exit status to the system.
44 if session.config.getoption(
"servercmd")
is None:
47 print(
'Waiting for server to finish...', flush=
True)
48 pytest.server_process.wait(timeout=0.5)
49 except subprocess.TimeoutExpired:
50 print(
'Server terminating by force...', flush=
True)
51 pytest.server_process.kill()
52 print(
'Server process stopped', flush=
True)
55def pytest_unconfigure(config):
57 called before test process is exited.