Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Python tests: skip the session hooks if --collect-only is used (cvat-…
Browse files Browse the repository at this point in the history
…ai#5550)

Turns out that cvat-ai#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.
  • Loading branch information
SpecLad authored and mikhail-treskin committed Jul 1, 2023
1 parent afffb1b commit 49983f8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions tests/python/shared/fixtures/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down Expand Up @@ -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":
Expand Down

0 comments on commit 49983f8

Please sign in to comment.