Skip to content

Commit d6cbc5e

Browse files
authored
Merge pull request #602 from powerapi-ng/build/ruff-pytest-rules
refactor: Fix `pytest` related ruff warnings
2 parents 670ca4e + c81fc76 commit d6cbc5e

File tree

9 files changed

+27
-32
lines changed

9 files changed

+27
-32
lines changed

.ruff.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,4 @@ ignore = [
2121
"RUF013", # implicit-optional
2222

2323
"B010", # set-attr-with-constant
24-
"PT001", # pytest-fixture-incorrect-parentheses-style
25-
"PT011", # pytest-raises-too-broad
26-
"PT012", # pytest-raises-with-multiple-statements
27-
"PT015", # pytest-assert-always-false
28-
"PT022", # pytest-useless-yield-fixture
2924
]

tests/unit/actor/abstract_test_actor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def pytest_generate_tests_abstract(metafunc):
140140
metafunc.parametrize('content', [[]])
141141

142142

143-
@pytest.fixture()
143+
@pytest.fixture
144144
def pusher(database):
145145
"""
146146
fixture that create a PusherActor before launching the test and stop it after the test end

tests/unit/actor/test_socket_interface.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ def check_socket(socket, socket_type, bind_address):
5050
assert socket_address == bind_address
5151

5252

53-
@pytest.fixture()
53+
@pytest.fixture
5454
def socket_interface():
5555
"""Return a socket interface not initialized
5656
5757
"""
5858
return SocketInterface(ACTOR_NAME, 100)
5959

6060

61-
@pytest.fixture()
61+
@pytest.fixture
6262
def initialized_socket_interface(socket_interface):
6363
"""Return an initialized socket interface
6464
@@ -70,7 +70,7 @@ def initialized_socket_interface(socket_interface):
7070
socket_interface.close()
7171

7272

73-
@pytest.fixture()
73+
@pytest.fixture
7474
def connected_interface(initialized_socket_interface):
7575
""" Return an initialized socket interface with an open connection to the
7676
push socket
@@ -81,7 +81,7 @@ def connected_interface(initialized_socket_interface):
8181
initialized_socket_interface.close()
8282

8383

84-
@pytest.fixture()
84+
@pytest.fixture
8585
def controlled_interface(initialized_socket_interface):
8686
""" Return an initialized socket interface with an open connection to the
8787
control socket
@@ -92,7 +92,7 @@ def controlled_interface(initialized_socket_interface):
9292
initialized_socket_interface.close()
9393

9494

95-
@pytest.fixture()
95+
@pytest.fixture
9696
def fully_connected_interface(initialized_socket_interface):
9797
""" Return an initialized socket interface with an open connection to the
9898
control and the push socket

tests/unit/actor/test_supervisor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def supervisor(request):
9999
"""
100100
supervisor = Supervisor()
101101
supervisor.actor_list = request.param
102-
yield supervisor
102+
return supervisor
103103

104104

105105
###############

tests/unit/cli/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def k8s_pre_processors(k8s_pre_processor_config):
286286
return processors
287287

288288

289-
@pytest.fixture()
289+
@pytest.fixture
290290
def subgroup_parser():
291291
"""
292292
A subgroup parser with one argument "-a"
@@ -505,7 +505,7 @@ def test_files_path():
505505
return test_files_module.__path__[0]
506506

507507

508-
@pytest.fixture()
508+
@pytest.fixture
509509
def cli_configuration(config_file: str):
510510
"""
511511
Load in sys.argv a configuration with arguments extracted from a json file
@@ -517,7 +517,7 @@ def cli_configuration(config_file: str):
517517
sys.argv = []
518518

519519

520-
@pytest.fixture()
520+
@pytest.fixture
521521
def empty_cli_configuration():
522522
"""
523523
Clean the CLI arguments

tests/unit/cli/test_binding_manager.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434

3535
from powerapi.cli.binding_manager import PreProcessorBindingManager
3636
from powerapi.dispatcher import DispatcherActor
37-
from powerapi.exception import UnsupportedActorTypeException, UnexistingActorException, \
38-
TargetActorAlreadyUsed
37+
from powerapi.exception import UnsupportedActorTypeException, UnexistingActorException, TargetActorAlreadyUsed
3938
from powerapi.processor.processor_actor import ProcessorActor
4039

4140

@@ -134,35 +133,36 @@ def test_check_processors_targets_are_unique_pass_without_reused_puller_in_bindi
134133
pytest.fail("Processors targets are not unique")
135134

136135

137-
def test_check_processor_targets_raise_exception_with_no_existing_puller(
138-
pre_processor_binding_manager_with_unexisting_puller):
136+
def check_all_processors_targets(preprocessor_binding_manager: PreProcessorBindingManager):
137+
"""
138+
Helper function that checks the processors targets of the given binding manager.
139+
"""
140+
for processor in preprocessor_binding_manager.processors.values():
141+
preprocessor_binding_manager.check_processor_targets(processor)
142+
143+
144+
def test_check_processor_targets_raise_exception_with_no_existing_puller(pre_processor_binding_manager_with_unexisting_puller):
139145
"""
140146
Test that an exception is raised with a puller that doesn't exist
141147
"""
142-
pre_processor_binding_manager = pre_processor_binding_manager_with_unexisting_puller
143148
with pytest.raises(UnexistingActorException):
144-
for _, processor in pre_processor_binding_manager.processors.items():
145-
pre_processor_binding_manager.check_processor_targets(processor=processor)
149+
check_all_processors_targets(pre_processor_binding_manager_with_unexisting_puller)
146150

147151

148-
def test_check_processor_targets_raise_exception_with_raise_exception_with_wrong_binding_types(
149-
pre_processor_binding_manager_with_wrong_binding_types):
152+
def test_check_processor_targets_raise_exception_with_raise_exception_with_wrong_binding_types(pre_processor_binding_manager_with_wrong_binding_types):
150153
"""
151154
Test that an exception is raised with a puller that doesn't exist
152155
"""
153-
pre_processor_binding_manager = pre_processor_binding_manager_with_wrong_binding_types
154156
with pytest.raises(UnsupportedActorTypeException):
155-
for _, processor in pre_processor_binding_manager.processors.items():
156-
pre_processor_binding_manager.check_processor_targets(processor=processor)
157+
check_all_processors_targets(pre_processor_binding_manager_with_wrong_binding_types)
157158

158159

159160
def test_check_processor_targets_pass_with_correct_targets(pre_processor_binding_manager):
160161
"""
161162
Test that validation of a configuration with existing targets of the correct type
162163
"""
163164
try:
164-
for _, processor in pre_processor_binding_manager.processors.items():
165-
pre_processor_binding_manager.check_processor_targets(processor=processor)
165+
check_all_processors_targets(pre_processor_binding_manager)
166166
except UnsupportedActorTypeException as e:
167167
pytest.fail(f'Unsupported actor type: {e}')
168168
except UnexistingActorException as e:

tests/unit/processor/pre/k8s/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ def initialized_monitor_agent(initialized_metadata_cache_manager):
5252
Returns an initialized monitor agent.
5353
"""
5454
agent = K8sMonitorAgent(initialized_metadata_cache_manager, 'manual', '', '')
55-
yield agent
55+
return agent

tests/unit/processor/pre/k8s/test_actor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def actor(self, request):
6363
actor.state.metadata_cache_manager = fx_initialized_metadata_cache_manager
6464
actor.state.manager = Mock()
6565
actor.state.monitor_agent = Mock()
66-
yield actor
66+
return actor
6767

6868
@staticmethod
6969
@pytest.mark.usefixtures("shutdown_system")

tests/utils/db/influx2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
INFLUX2_MEASUREMENT_NAME = 'power_consumption'
6464

6565

66-
@pytest.fixture()
66+
@pytest.fixture
6767
def influx2_database():
6868
"""
6969
connect to a local influx database (localhost:8086) and store data contained in the list influxdb_content

0 commit comments

Comments
 (0)