From 8d83b67c2feb539af7566d05e84b1cc154732996 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Wed, 12 Jul 2023 05:48:42 +0200 Subject: test: move some code to lib/ --- test/py/test_repo.py | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) (limited to 'test/py/test_repo.py') diff --git a/test/py/test_repo.py b/test/py/test_repo.py index aa89261..4fd6b09 100644 --- a/test/py/test_repo.py +++ b/test/py/test_repo.py @@ -11,6 +11,13 @@ import pytest from lib.logging import child_logging_thread, configure_logging_in_child from lib.process import LoggingEvent +from lib.tests import my_parametrize + + +def test_sigsegv(sigsegv): + ec, output = sigsegv.try_run() + assert ec == -11 + assert output == 'Started the test program.\n' class LoggingEventRunComplete(LoggingEvent): @@ -29,7 +36,7 @@ class LoggingEventRunComplete(LoggingEvent): super().set() -def client_runner(log_queue, client, runs_per_process, repo): +def client_runner_process(log_queue, client, runs_per_process, repo): with configure_logging_in_child(log_queue): logging.info('Executing %s clients', runs_per_process) for i in range(runs_per_process): @@ -46,12 +53,11 @@ def _test_repo_internal(env, repo, numof_processes, runs_per_process): with child_logging_thread() as log_queue: ctx = mp.get_context('spawn') args = (log_queue, env.client, runs_per_process, repo) - processes = [ctx.Process(target=client_runner, args=args) for i in range(numof_processes)] + processes = [ctx.Process(target=client_runner_process, args=args) for i in range(numof_processes)] + for proc in processes: proc.start() - event.wait() - for proc in processes: proc.join() @@ -66,27 +72,6 @@ def _test_repo_internal(env, repo, numof_processes, runs_per_process): assert repo.run_output_matches(output), f"Output doesn't match: {output}" -# Reference: https://github.com/pytest-dev/pytest/issues/3628 -# Automatic generation of readable test IDs. -def my_parametrize(names, values, ids=None, **kwargs): - _names = names.split(',') if isinstance(names, str) else names - if not ids: - if len(_names) == 1: - ids = [f'{names}={v}' for v in values] - else: - ids = [ - '-'.join(f'{k}={v}' for k, v in zip(_names, combination)) - for combination in values - ] - return pytest.mark.parametrize(names, values, ids=ids, **kwargs) - - -def test_sigsegv(sigsegv): - ec, output = sigsegv.try_run() - assert ec == -11 - assert output == 'Started the test program.\n' - - @my_parametrize('runs_per_client', [1, 5]) @my_parametrize('numof_clients', [1, 5]) def test_repo(env, test_repo, numof_clients, runs_per_client): -- cgit v1.2.3