diff --git a/.github/dependabot.yml b/.github/dependabot.yml index eadcd59879..d375588780 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -12,6 +12,12 @@ updates: - dependency-name: pytest versions: - "> 3.7.3" + - dependency-name: flake8 # Later versions dropped Python 2 support + versions: + - "> 5.0.4" + - dependency-name: jsonschema # Later versions dropped Python 2 support + versions: + - "> 3.2.0" - dependency-name: pytest-cov versions: - "> 2.8.1" @@ -43,6 +49,6 @@ updates: open-pull-requests-limit: 10 - package-ecosystem: "github-actions" directory: "/" - schedule: + schedule: interval: weekly open-pull-requests-limit: 10 diff --git a/linter-requirements.txt b/linter-requirements.txt index 9ba7fa1cf2..d1108f8eae 100644 --- a/linter-requirements.txt +++ b/linter-requirements.txt @@ -1,11 +1,11 @@ -mypy==1.5.1 -black==23.7.0 -flake8==5.0.4 +mypy +black +flake8==5.0.4 # flake8 depends on pyflakes>=3.0.0 and this dropped support for Python 2 "# type:" comments types-certifi types-redis types-setuptools pymongo # There is no separate types module. loguru # There is no separate types module. -flake8-bugbear==22.12.6 -pep8-naming==0.13.2 +flake8-bugbear +pep8-naming pre-commit # local linting diff --git a/tests/integrations/celery/test_celery.py b/tests/integrations/celery/test_celery.py index f97132f1a6..b13e19ebaa 100644 --- a/tests/integrations/celery/test_celery.py +++ b/tests/integrations/celery/test_celery.py @@ -375,7 +375,7 @@ def dummy_task(self): # Curious: Cannot use delay() here or py2.7-celery-4.2 crashes res = dummy_task.apply_async() - with pytest.raises(Exception): + with pytest.raises(Exception): # noqa: B017 # Celery 4.1 raises a gibberish exception res.wait() diff --git a/tests/integrations/logging/test_logging.py b/tests/integrations/logging/test_logging.py index de1c55e26f..92d0674c09 100644 --- a/tests/integrations/logging/test_logging.py +++ b/tests/integrations/logging/test_logging.py @@ -185,11 +185,11 @@ def test_logging_captured_warnings(sentry_init, capture_events, recwarn): events = capture_events() logging.captureWarnings(True) - warnings.warn("first") - warnings.warn("second") + warnings.warn("first", stacklevel=2) + warnings.warn("second", stacklevel=2) logging.captureWarnings(False) - warnings.warn("third") + warnings.warn("third", stacklevel=2) assert len(events) == 2 diff --git a/tests/integrations/stdlib/test_httplib.py b/tests/integrations/stdlib/test_httplib.py index 8072bf2773..d50bf42e21 100644 --- a/tests/integrations/stdlib/test_httplib.py +++ b/tests/integrations/stdlib/test_httplib.py @@ -114,7 +114,7 @@ def test_httplib_misuse(sentry_init, capture_events, request): conn.request("GET", "/200") - with pytest.raises(Exception): + with pytest.raises(Exception): # noqa: B017 # This raises an exception, because we didn't call `getresponse` for # the previous request yet. # diff --git a/tests/integrations/wsgi/test_wsgi.py b/tests/integrations/wsgi/test_wsgi.py index 3616c7cc2f..0b76bf6887 100644 --- a/tests/integrations/wsgi/test_wsgi.py +++ b/tests/integrations/wsgi/test_wsgi.py @@ -126,21 +126,21 @@ def test_transaction_with_error( sentry_init, crashing_app, capture_events, DictionaryContaining # noqa:N803 ): def dogpark(environ, start_response): - raise Exception("Fetch aborted. The ball was not returned.") + raise ValueError("Fetch aborted. The ball was not returned.") sentry_init(send_default_pii=True, traces_sample_rate=1.0) app = SentryWsgiMiddleware(dogpark) client = Client(app) events = capture_events() - with pytest.raises(Exception): + with pytest.raises(ValueError): client.get("http://dogs.are.great/sit/stay/rollover/") error_event, envelope = events assert error_event["transaction"] == "generic WSGI request" assert error_event["contexts"]["trace"]["op"] == "http.server" - assert error_event["exception"]["values"][0]["type"] == "Exception" + assert error_event["exception"]["values"][0]["type"] == "ValueError" assert error_event["exception"]["values"][0]["mechanism"]["type"] == "wsgi" assert error_event["exception"]["values"][0]["mechanism"]["handled"] is False assert ( @@ -189,14 +189,14 @@ def test_has_trace_if_performance_enabled( ): def dogpark(environ, start_response): capture_message("Attempting to fetch the ball") - raise Exception("Fetch aborted. The ball was not returned.") + raise ValueError("Fetch aborted. The ball was not returned.") sentry_init(traces_sample_rate=1.0) app = SentryWsgiMiddleware(dogpark) client = Client(app) events = capture_events() - with pytest.raises(Exception): + with pytest.raises(ValueError): client.get("http://dogs.are.great/sit/stay/rollover/") msg_event, error_event, transaction_event = events @@ -223,14 +223,14 @@ def test_has_trace_if_performance_disabled( ): def dogpark(environ, start_response): capture_message("Attempting to fetch the ball") - raise Exception("Fetch aborted. The ball was not returned.") + raise ValueError("Fetch aborted. The ball was not returned.") sentry_init() app = SentryWsgiMiddleware(dogpark) client = Client(app) events = capture_events() - with pytest.raises(Exception): + with pytest.raises(ValueError): client.get("http://dogs.are.great/sit/stay/rollover/") msg_event, error_event = events @@ -248,7 +248,7 @@ def test_trace_from_headers_if_performance_enabled( ): def dogpark(environ, start_response): capture_message("Attempting to fetch the ball") - raise Exception("Fetch aborted. The ball was not returned.") + raise ValueError("Fetch aborted. The ball was not returned.") sentry_init(traces_sample_rate=1.0) app = SentryWsgiMiddleware(dogpark) @@ -258,7 +258,7 @@ def dogpark(environ, start_response): trace_id = "582b43a4192642f0b136d5159a501701" sentry_trace_header = "{}-{}-{}".format(trace_id, "6e8f22c393e68f19", 1) - with pytest.raises(Exception): + with pytest.raises(ValueError): client.get( "http://dogs.are.great/sit/stay/rollover/", headers={"sentry-trace": sentry_trace_header}, @@ -286,7 +286,7 @@ def test_trace_from_headers_if_performance_disabled( ): def dogpark(environ, start_response): capture_message("Attempting to fetch the ball") - raise Exception("Fetch aborted. The ball was not returned.") + raise ValueError("Fetch aborted. The ball was not returned.") sentry_init() app = SentryWsgiMiddleware(dogpark) @@ -296,7 +296,7 @@ def dogpark(environ, start_response): trace_id = "582b43a4192642f0b136d5159a501701" sentry_trace_header = "{}-{}-{}".format(trace_id, "6e8f22c393e68f19", 1) - with pytest.raises(Exception): + with pytest.raises(ValueError): client.get( "http://dogs.are.great/sit/stay/rollover/", headers={"sentry-trace": sentry_trace_header}, diff --git a/tests/test_crons.py b/tests/test_crons.py index c7c8ea96b4..9ea98df2ac 100644 --- a/tests/test_crons.py +++ b/tests/test_crons.py @@ -61,7 +61,7 @@ def test_decorator_error(sentry_init): with mock.patch( "sentry_sdk.crons.decorator.capture_checkin" ) as fake_capture_checking: - with pytest.raises(Exception): + with pytest.raises(ZeroDivisionError): result = _break_world("Grace") assert "result" not in locals() @@ -109,7 +109,7 @@ def test_contextmanager_error(sentry_init): with mock.patch( "sentry_sdk.crons.decorator.capture_checkin" ) as fake_capture_checking: - with pytest.raises(Exception): + with pytest.raises(ZeroDivisionError): result = _break_world_contextmanager("Grace") assert "result" not in locals()