Skip to content

Commit 0e6ac7f

Browse files
committed
Fix warning about TestEnv being interpreted as a test
The `TestEnv` class actually holds just stuff that it is reused in different test, but `pytest` integret classes starting with `Test` as test suites. We just rename to `_TestEnv` to avoid the confusion (and warnings). Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 0a3b729 commit 0e6ac7f

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

tests/test_frequenz_dispatch.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def _now() -> datetime:
5555

5656

5757
@dataclass(frozen=True)
58-
class TestEnv:
58+
class _TestEnv:
5959
"""Test environment for the service."""
6060

6161
service: DispatchScheduler
@@ -71,7 +71,7 @@ class TestEnv:
7171

7272

7373
@fixture
74-
async def test_env() -> AsyncIterator[TestEnv]:
74+
async def test_env() -> AsyncIterator[_TestEnv]:
7575
"""Return an actor test environment."""
7676
microgrid_id = randint(1, 100)
7777
client = FakeClient()
@@ -83,7 +83,7 @@ async def test_env() -> AsyncIterator[TestEnv]:
8383

8484
service.start()
8585
try:
86-
yield TestEnv(
86+
yield _TestEnv(
8787
service=service,
8888
lifecycle_events=service.new_lifecycle_events_receiver("TEST_TYPE"),
8989
running_state_change=await service.new_running_state_event_receiver(
@@ -103,7 +103,7 @@ def generator() -> DispatchGenerator:
103103

104104

105105
async def test_new_dispatch_created(
106-
test_env: TestEnv,
106+
test_env: _TestEnv,
107107
generator: DispatchGenerator,
108108
) -> None:
109109
"""Test that a new dispatch is created."""
@@ -131,7 +131,7 @@ def update_dispatch(sample: BaseDispatch, dispatch: BaseDispatch) -> BaseDispatc
131131

132132

133133
async def _test_new_dispatch_created(
134-
test_env: TestEnv,
134+
test_env: _TestEnv,
135135
sample: BaseDispatch,
136136
) -> Dispatch:
137137
"""Test that a new dispatch is created.
@@ -159,7 +159,7 @@ async def _test_new_dispatch_created(
159159

160160

161161
async def test_existing_dispatch_updated(
162-
test_env: TestEnv,
162+
test_env: _TestEnv,
163163
generator: DispatchGenerator,
164164
fake_time: time_machine.Coordinates,
165165
) -> None:
@@ -197,7 +197,7 @@ async def test_existing_dispatch_updated(
197197

198198

199199
async def test_existing_dispatch_deleted(
200-
test_env: TestEnv,
200+
test_env: _TestEnv,
201201
generator: DispatchGenerator,
202202
fake_time: time_machine.Coordinates,
203203
) -> None:
@@ -220,7 +220,7 @@ async def test_existing_dispatch_deleted(
220220

221221

222222
async def test_dispatch_inf_duration_deleted(
223-
test_env: TestEnv,
223+
test_env: _TestEnv,
224224
generator: DispatchGenerator,
225225
fake_time: time_machine.Coordinates,
226226
) -> None:
@@ -255,7 +255,7 @@ async def test_dispatch_inf_duration_deleted(
255255

256256

257257
async def test_dispatch_inf_duration_updated_stopped_started(
258-
test_env: TestEnv,
258+
test_env: _TestEnv,
259259
generator: DispatchGenerator,
260260
fake_time: time_machine.Coordinates,
261261
) -> None:
@@ -304,7 +304,7 @@ async def test_dispatch_inf_duration_updated_stopped_started(
304304

305305

306306
async def test_dispatch_inf_duration_updated_to_finite_and_stops(
307-
test_env: TestEnv,
307+
test_env: _TestEnv,
308308
generator: DispatchGenerator,
309309
fake_time: time_machine.Coordinates,
310310
) -> None:
@@ -347,7 +347,7 @@ async def test_dispatch_inf_duration_updated_to_finite_and_stops(
347347

348348

349349
async def test_dispatch_schedule(
350-
test_env: TestEnv,
350+
test_env: _TestEnv,
351351
generator: DispatchGenerator,
352352
fake_time: time_machine.Coordinates,
353353
) -> None:
@@ -385,7 +385,7 @@ async def test_dispatch_schedule(
385385

386386

387387
async def test_dispatch_inf_duration_updated_to_finite_and_continues(
388-
test_env: TestEnv,
388+
test_env: _TestEnv,
389389
generator: DispatchGenerator,
390390
fake_time: time_machine.Coordinates,
391391
) -> None:
@@ -432,7 +432,7 @@ async def test_dispatch_inf_duration_updated_to_finite_and_continues(
432432

433433

434434
async def test_dispatch_new_but_finished(
435-
test_env: TestEnv,
435+
test_env: _TestEnv,
436436
generator: DispatchGenerator,
437437
fake_time: time_machine.Coordinates,
438438
) -> None:
@@ -490,7 +490,7 @@ async def test_dispatch_new_but_finished(
490490

491491

492492
async def test_notification_on_actor_start(
493-
test_env: TestEnv,
493+
test_env: _TestEnv,
494494
generator: DispatchGenerator,
495495
fake_time: time_machine.Coordinates,
496496
) -> None:

tests/test_mananging_actor.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ async def create_fail(
9393

9494

9595
@dataclass
96-
class TestEnv:
96+
class _TestEnv:
9797
"""Test environment."""
9898

9999
actors_service: ActorDispatcher
@@ -109,7 +109,7 @@ def actor(self, identity: int) -> MockActor:
109109

110110

111111
@fixture
112-
async def test_env() -> AsyncIterator[TestEnv]:
112+
async def test_env() -> AsyncIterator[_TestEnv]:
113113
"""Create a test environment."""
114114
channel = Broadcast[Dispatch](name="dispatch ready test channel")
115115

@@ -122,7 +122,7 @@ async def test_env() -> AsyncIterator[TestEnv]:
122122
actors_service.start()
123123
await asyncio.sleep(1)
124124

125-
yield TestEnv(
125+
yield _TestEnv(
126126
actors_service=actors_service,
127127
running_status_sender=channel.new_sender(),
128128
)
@@ -131,7 +131,7 @@ async def test_env() -> AsyncIterator[TestEnv]:
131131

132132

133133
async def test_simple_start_stop(
134-
test_env: TestEnv,
134+
test_env: _TestEnv,
135135
fake_time: time_machine.Coordinates,
136136
) -> None:
137137
"""Test behavior when receiving start/stop messages."""
@@ -178,7 +178,7 @@ async def test_simple_start_stop(
178178

179179

180180
async def test_start_failed(
181-
test_env: TestEnv, fake_time: time_machine.Coordinates
181+
test_env: _TestEnv, fake_time: time_machine.Coordinates
182182
) -> None:
183183
"""Test auto-retry after 60 seconds."""
184184
# pylint: disable=protected-access
@@ -218,7 +218,7 @@ async def test_start_failed(
218218
assert test_env.actor(1).is_running is True
219219

220220

221-
def test_heapq_dispatch_compare(test_env: TestEnv) -> None:
221+
def test_heapq_dispatch_compare(test_env: _TestEnv) -> None:
222222
"""Test that the heapq compare function works."""
223223
dispatch1 = test_env.generator.generate_dispatch()
224224
dispatch2 = test_env.generator.generate_dispatch()
@@ -241,7 +241,7 @@ def test_heapq_dispatch_compare(test_env: TestEnv) -> None:
241241
)
242242

243243

244-
def test_heapq_dispatch_start_stop_compare(test_env: TestEnv) -> None:
244+
def test_heapq_dispatch_start_stop_compare(test_env: _TestEnv) -> None:
245245
"""Test that the heapq compare function works."""
246246
dispatch1 = test_env.generator.generate_dispatch()
247247
dispatch2 = test_env.generator.generate_dispatch()
@@ -267,7 +267,7 @@ def test_heapq_dispatch_start_stop_compare(test_env: TestEnv) -> None:
267267
assert scheduled_events[1].dispatch_id == dispatch2.id
268268

269269

270-
async def test_dry_run(test_env: TestEnv, fake_time: time_machine.Coordinates) -> None:
270+
async def test_dry_run(test_env: _TestEnv, fake_time: time_machine.Coordinates) -> None:
271271
"""Test the dry run mode."""
272272
dispatch = test_env.generator.generate_dispatch()
273273
dispatch = replace(

0 commit comments

Comments
 (0)