Python tests: skip the session hooks if --collect-only is used (#5550)

Turns out that #5456 had a nasty side effect. Session hooks are called
when pytest is run with `--collect-only` (even though no tests are
actually run in this case), and Visual Studio Code periodically runs
`pytest --collect-only` in order to learn what tests exist in the
project. As a result, it keeps restarting the services and restoring the
database in the background.

Work around this by skipping all logic in the hooks if `--collect-only`
is in the options.
main
Roman Donchenko 3 years ago committed by GitHub
parent 1071e2379c
commit 0ea14d23a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -259,12 +259,21 @@ def start_services(rebuild=False):
docker_cp(CVAT_DB_DIR / "data.json", f"{PREFIX}_cvat_server_1:/tmp/data.json")
def pytest_sessionstart(session):
def pytest_sessionstart(session: pytest.Session) -> None:
stop = session.config.getoption("--stop-services")
start = session.config.getoption("--start-services")
rebuild = session.config.getoption("--rebuild")
cleanup = session.config.getoption("--cleanup")
dumpdb = session.config.getoption("--dumpdb")
if session.config.getoption("--collect-only"):
if any((stop, start, rebuild, cleanup, dumpdb)):
raise Exception(
"""--collect-only is not compatible with any of the other options:
--stop-services --start-services --rebuild --cleanup --dumpdb"""
)
return # don't need to start the services to collect tests
platform = session.config.getoption("--platform")
if platform == "kube" and any((stop, start, rebuild, cleanup, dumpdb)):
@ -338,7 +347,10 @@ def pytest_sessionstart(session):
)
def pytest_sessionfinish(session, exitstatus):
def pytest_sessionfinish(session: pytest.Session, exitstatus: int) -> None:
if session.config.getoption("--collect-only"):
return
platform = session.config.getoption("--platform")
if platform == "local":

Loading…
Cancel
Save