|
1 | 1 | # Copyright 2023 Open Source Robotics Foundation, Inc.
|
2 | 2 | # Licensed under the Apache License, Version 2.0
|
3 | 3 |
|
| 4 | +import asyncio |
4 | 5 | import logging
|
5 | 6 | import os
|
6 | 7 | import unittest.mock
|
7 | 8 | import warnings
|
8 | 9 |
|
9 | 10 | from colcon_core.package_descriptor import PackageDescriptor
|
| 11 | +from colcon_core.subprocess import new_event_loop |
10 | 12 | from colcon_python_project.hook_caller_decorator.setuptools \
|
11 | 13 | import SetuptoolsHookCallerDecoratorExtension
|
12 | 14 | import pytest
|
|
15 | 17 | from .backend_fixtures import MOCK_BACKENDS
|
16 | 18 |
|
17 | 19 |
|
| 20 | +@pytest.fixture |
| 21 | +def colcon_event_loop(): |
| 22 | + loop = new_event_loop() |
| 23 | + asyncio.set_event_loop(loop) |
| 24 | + yield loop |
| 25 | + loop.run_until_complete(loop.shutdown_asyncgens()) |
| 26 | + asyncio.set_event_loop(None) |
| 27 | + loop.close() |
| 28 | + |
| 29 | + |
18 | 30 | @pytest.fixture(autouse=True)
|
19 | 31 | def better_benchmarking(request):
|
20 | 32 | if 'benchmark' not in request.fixturenames:
|
@@ -55,10 +67,11 @@ def override_extensions(group_name, *args, **kwargs):
|
55 | 67 |
|
56 | 68 |
|
57 | 69 | @pytest.fixture
|
58 |
| -def bench(benchmark, event_loop): |
| 70 | +def bench(benchmark, colcon_event_loop): |
59 | 71 | def res(target, *args, **kwargs):
|
60 | 72 | def dut():
|
61 |
| - return event_loop.run_until_complete(target(*args, **kwargs)) |
| 73 | + return colcon_event_loop.run_until_complete( |
| 74 | + target(*args, **kwargs)) |
62 | 75 | return benchmark(dut)
|
63 | 76 | return res
|
64 | 77 |
|
|
0 commit comments