Skip to content

Commit 0594303

Browse files
authored
Merge pull request #1372 from newrelic/fix-linter-pyteststyle
Enable linter flake8-pytest-style
2 parents dfd95ab + 7e6dda8 commit 0594303

File tree

79 files changed

+268
-265
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+268
-265
lines changed

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ select = [
5959
"G", # flake8-logging-format
6060
"INP", # flake8-no-pep420
6161
"PYI", # flake8-pyi
62-
# "PT", # flake8-pytest-style
62+
"PT", # flake8-pytest-style
6363
"Q", # flake8-quotes
6464
"RSE", # flake8-raise
6565
# "RET", # flake8-return
@@ -101,13 +101,13 @@ select = [
101101

102102
ignore = [
103103
# Temporarily disabled rules
104-
"RUF100", # unused-noqa (TODO: remove this once all linters are enabled)
105104
"PERF203", # try-except-in-loop (most of these are unavoidable)
106105
"S110", # try-except-pass (Bandit wants us to log the exception, which is usually pointless. Spot check these later)
107106
"PLW0603", # global-statement (this is currently used extensively)
108107
"PLW2901", # redefined-loop-name (frequently used, not generally an issue)
109108
"PLR", # Pylint Recommendations (too many to fix all at once)
110109
"E722", # bare-except (too many to fix all at once)
110+
"PT012", # pytest-raises-with-multiple-statements (too many to fix all at once)
111111
# Permanently disabled rules
112112
"UP006", # non-pep585-annotation (not compatible with Python 3.7 or 3.8)
113113
"D203", # incorrect-blank-line-before-class
@@ -144,6 +144,9 @@ ignore = [
144144
"PLR2004", # magic-value-comparison (comparing to constant values)
145145
"ASYNC251", # blocking-sleep-in-async-function (acceptable in tests)
146146
"B904", # raise-without-from-inside-except (not necessary in tests)
147+
"PT006", # pytest-parametrize-names-wrong-type (style choice)
148+
"PT007", # pytest-parametrize-values-wrong-type (style choice)
149+
"PT011", # pytest-raises-too-broad (we frequently test for generic errors)
147150
]
148151
"newrelic/admin/*" = [
149152
# Disabled rules in admin scripts

tests/agent_features/test_async_generator_trace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ async def _test():
273273
await gen.asend(None)
274274

275275
assert await gen.asend("foobar") == "foobar"
276-
assert _received and _received[0] == "foobar"
276+
assert _received[0] == "foobar"
277277

278278
# finish consumption of the coroutine if necessary
279279
async for _ in gen:

tests/agent_features/test_configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
SKIP_IF_NOT_PY311 = pytest.mark.skipif(sys.version_info < (3, 11), reason="TOML not in the standard library.")
4848

4949

50-
@pytest.fixture(scope="function")
50+
@pytest.fixture
5151
def collector_available_fixture():
5252
# Disable fixture that requires real application to exist for this file
5353
pass

tests/agent_features/test_logs_in_context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def test_newrelic_logger_error_inside_transaction_with_stack_trace(log_buffer_wi
241241
assert filename.endswith("/test_logs_in_context.py")
242242
assert isinstance(line_number, int)
243243
assert isinstance(stack_trace, str)
244-
assert stack_trace and stack_trace == expected_stack_trace
244+
assert stack_trace == expected_stack_trace
245245

246246
expected = {
247247
"entity.name": "Python Agent Test (agent_features)",
@@ -329,7 +329,7 @@ def test_newrelic_logger_error_outside_transaction_with_stack_trace(log_buffer_w
329329
assert filename.endswith("/test_logs_in_context.py")
330330
assert isinstance(line_number, int)
331331
assert isinstance(stack_trace, str)
332-
assert stack_trace and stack_trace == expected_stack_trace
332+
assert stack_trace == expected_stack_trace
333333

334334
expected = {
335335
"entity.name": "Python Agent Test (agent_features)",

tests/agent_features/test_metric_normalization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def core_app(collector_agent_registration):
4040
return app._agent.application(app.name)
4141

4242

43-
@pytest.fixture(scope="function")
43+
@pytest.fixture
4444
def rules_engine_fixture(core_app):
4545
rules_engine = core_app._rules_engine
4646
previous_rules = rules_engine["metric"]

tests/agent_features/test_serverless_mode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from newrelic.core.config import global_settings
2929

3030

31-
@pytest.fixture(scope="function")
31+
@pytest.fixture
3232
def serverless_application(request):
3333
settings = global_settings()
3434
orig = settings.serverless_mode.enabled

tests/agent_features/test_web_transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def test_base_web_transaction(use_bytes):
141141
transaction.process_response(200, response_headers)
142142

143143

144-
@pytest.fixture()
144+
@pytest.fixture
145145
def validate_no_garbage():
146146
yield
147147

tests/agent_streaming/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def wait(self, *args, **kwargs):
6868
return super().wait(*args, **kwargs)
6969

7070

71-
@pytest.fixture(scope="function")
71+
@pytest.fixture
7272
def buffer_empty_event(monkeypatch):
7373
event = threading.Event()
7474

@@ -85,23 +85,23 @@ def batching(request):
8585
return request.param
8686

8787

88-
@pytest.fixture(scope="function")
88+
@pytest.fixture
8989
def spans_received():
9090
from _test_handler import SPANS_RECEIVED
9191

9292
SPANS_RECEIVED.clear()
9393
return SPANS_RECEIVED
9494

9595

96-
@pytest.fixture(scope="function")
96+
@pytest.fixture
9797
def span_batches_received():
9898
from _test_handler import SPAN_BATCHES_RECEIVED
9999

100100
SPAN_BATCHES_RECEIVED.clear()
101101
return SPAN_BATCHES_RECEIVED
102102

103103

104-
@pytest.fixture(scope="function")
104+
@pytest.fixture
105105
def spans_processed_event():
106106
from _test_handler import SPANS_PROCESSED_EVENT
107107

tests/agent_streaming/test_infinite_tracing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
CONDITION_CLS = type(threading.Condition())
3232

3333

34-
@pytest.fixture()
34+
@pytest.fixture
3535
def app():
3636
app = Application("Python Agent Test (Infinite Tracing)")
3737
yield app

tests/agent_streaming/test_stream_buffer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def stop_iteration_condition(*args, **kwargs):
2929
return StopIterationOnWait(*args, **kwargs)
3030

3131

32-
@pytest.fixture(scope="function")
32+
@pytest.fixture
3333
def stop_iteration_on_wait(monkeypatch):
3434
monkeypatch.setattr(StreamBuffer, "condition", stop_iteration_condition)
3535

0 commit comments

Comments
 (0)