Skip to content

Commit

Permalink
Convert the "services" fixture into sessionstart/sessionfinish hooks
Browse files Browse the repository at this point in the history
This makes the test output less messy. Fixtures are only created after the
first test starts running, so `docker-compose` output becomes intermixed
with the test log. The hooks, on the other hand, run before the tests are
even collected, so the output is separated from the test log.

This also makes runs with options like `--stop-services` a bit faster,
because pytest doesn't have to waste time collecting tests that won't even
be run.
  • Loading branch information
SpecLad committed Dec 13, 2022
1 parent fe0a703 commit ed338b0
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions tests/python/shared/fixtures/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,13 @@ def start_services(rebuild=False):
docker_cp(CVAT_DB_DIR / "data.json", f"{PREFIX}_cvat_server_1:/tmp/data.json")


@pytest.fixture(autouse=True, scope="session")
def services(request):
stop = request.config.getoption("--stop-services")
start = request.config.getoption("--start-services")
rebuild = request.config.getoption("--rebuild")
cleanup = request.config.getoption("--cleanup")
dumpdb = request.config.getoption("--dumpdb")
platform = request.config.getoption("--platform")
def pytest_sessionstart(session):
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")
platform = session.config.getoption("--platform")

if platform == "kube" and any((stop, start, rebuild, cleanup, dumpdb)):
raise Exception(
Expand Down Expand Up @@ -297,11 +296,6 @@ def services(request):
if start:
pytest.exit("All necessary containers have been created and started.", returncode=0)

yield

docker_restore_db()
docker_exec_cvat_db("dropdb test_db")

elif platform == "kube":
kube_restore_data_volumes()
server_pod_name = _kube_get_server_pod_name()
Expand All @@ -321,7 +315,13 @@ def services(request):
]
)

yield

def pytest_sessionfinish(session, exitstatus):
platform = session.config.getoption("--platform")

if platform == "local":
docker_restore_db()
docker_exec_cvat_db("dropdb test_db")


@pytest.fixture(scope="function")
Expand Down

0 comments on commit ed338b0

Please sign in to comment.