From 217a73237008131cb68bfa39250c4de856fe5104 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Fri, 9 Oct 2020 14:23:11 -0700 Subject: [PATCH 1/6] add pytest-watch --- pytest.ini | 7 +++++++ test-requirements.txt | 1 + tests/integrations/gcp/test_gcp.py | 2 ++ tests/integrations/stdlib/test_httplib.py | 2 ++ 4 files changed, 12 insertions(+) diff --git a/pytest.ini b/pytest.ini index 19cf3a00e8..06da455b9b 100644 --- a/pytest.ini +++ b/pytest.ini @@ -2,3 +2,10 @@ DJANGO_SETTINGS_MODULE = tests.integrations.django.myapp.settings addopts = --tb=short markers = tests_internal_exceptions + +[pytest-watch] +; Enable this to drop into pdb on errors +; pdb = True + +verbose = True +nobeep = True diff --git a/test-requirements.txt b/test-requirements.txt index bd518645e2..8d241eb7a6 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,5 +1,6 @@ pytest==3.7.3 pytest-forked==1.1.3 +pytest-watch==4.2.0 tox==3.7.0 Werkzeug==0.15.5 pytest-localserver==0.5.0 diff --git a/tests/integrations/gcp/test_gcp.py b/tests/integrations/gcp/test_gcp.py index fa234a0da3..bad796d833 100644 --- a/tests/integrations/gcp/test_gcp.py +++ b/tests/integrations/gcp/test_gcp.py @@ -123,6 +123,8 @@ def inner(code, subprocess_kwargs=()): else: continue + stream.close() + return envelope, event return inner diff --git a/tests/integrations/stdlib/test_httplib.py b/tests/integrations/stdlib/test_httplib.py index a8d9a6a458..5165d2e6e6 100644 --- a/tests/integrations/stdlib/test_httplib.py +++ b/tests/integrations/stdlib/test_httplib.py @@ -106,3 +106,5 @@ def test_httplib_misuse(sentry_init, capture_events): "status_code": 200, "reason": "OK", } + + conn.close() From 0b7fcbb8eae93e37d6e4a4ff8a7505a838a8e4d5 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Mon, 12 Oct 2020 10:04:37 -0700 Subject: [PATCH 2/6] use request fixture to ensure connection closure --- tests/integrations/stdlib/test_httplib.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/integrations/stdlib/test_httplib.py b/tests/integrations/stdlib/test_httplib.py index 5165d2e6e6..ab3d969756 100644 --- a/tests/integrations/stdlib/test_httplib.py +++ b/tests/integrations/stdlib/test_httplib.py @@ -67,7 +67,7 @@ def before_breadcrumb(crumb, hint): assert sys.getrefcount(response) == 2 -def test_httplib_misuse(sentry_init, capture_events): +def test_httplib_misuse(sentry_init, capture_events, request): """HTTPConnection.getresponse must be called after every call to HTTPConnection.request. However, if somebody does not abide by this contract, we still should handle this gracefully and not @@ -81,6 +81,10 @@ def test_httplib_misuse(sentry_init, capture_events): events = capture_events() conn = HTTPSConnection("httpbin.org", 443) + + # make sure we release the resource, even if the test fails + request.addfinalizer(lambda: conn.close()) + conn.request("GET", "/anything/foo") with pytest.raises(Exception): @@ -106,5 +110,3 @@ def test_httplib_misuse(sentry_init, capture_events): "status_code": 200, "reason": "OK", } - - conn.close() From 605ca7dc12a08cb5521a2b5e3fc373ef78071068 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Mon, 12 Oct 2020 10:08:41 -0700 Subject: [PATCH 3/6] remove unnecessary lambda --- tests/integrations/stdlib/test_httplib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integrations/stdlib/test_httplib.py b/tests/integrations/stdlib/test_httplib.py index ab3d969756..d62613566c 100644 --- a/tests/integrations/stdlib/test_httplib.py +++ b/tests/integrations/stdlib/test_httplib.py @@ -83,7 +83,7 @@ def test_httplib_misuse(sentry_init, capture_events, request): conn = HTTPSConnection("httpbin.org", 443) # make sure we release the resource, even if the test fails - request.addfinalizer(lambda: conn.close()) + request.addfinalizer(conn.close) conn.request("GET", "/anything/foo") From 2a0cc407a5889b6ae6afa92619b9164ee81011c9 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 28 Mar 2022 10:57:47 +0200 Subject: [PATCH 4/6] fix(tests): trying to remove pinned depencies because maybe they are not necessary anymore --- tox.ini | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tox.ini b/tox.ini index bc087ad23c..5b5f18be55 100644 --- a/tox.ini +++ b/tox.ini @@ -307,12 +307,6 @@ commands = {py3.5,py3.6,py3.7,py3.8,py3.9}-flask-{0.10,0.11,0.12}: pip install pytest<5 {py3.6,py3.7,py3.8,py3.9}-flask-{0.11}: pip install Werkzeug<2 - ; https://github.com/pallets/flask/issues/4455 - {py3.7,py3.8,py3.9,py3.10}-flask-{0.11,0.12,1.0,1.1}: pip install "itsdangerous>=0.24,<2.0" "markupsafe<2.0.0" - ;"itsdangerous >= 0.24, < 2.0", -;itsdangerous==1.1.0 -;markupsafe==1.1.1 - ; https://github.com/more-itertools/more-itertools/issues/578 py3.5-flask-{0.10,0.11,0.12}: pip install more-itertools<8.11.0 From 90a007a4920d3e53e0b96ec8a72770ba66c9d1ec Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 28 Mar 2022 11:13:40 +0200 Subject: [PATCH 5/6] fix(tests): fixing Flask dependencies for tests to work. --- tox.ini | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tox.ini b/tox.ini index 5b5f18be55..a3a46eaa44 100644 --- a/tox.ini +++ b/tox.ini @@ -307,6 +307,9 @@ commands = {py3.5,py3.6,py3.7,py3.8,py3.9}-flask-{0.10,0.11,0.12}: pip install pytest<5 {py3.6,py3.7,py3.8,py3.9}-flask-{0.11}: pip install Werkzeug<2 + ; https://github.com/pallets/flask/issues/4455 + {py3.7,py3.8,py3.9,py3.10}-flask-{0.11,0.12,1.0,1.1}: pip install "itsdangerous>=0.24,<2.0" "markupsafe<2.0.0" "jinja2<3.1.1" + ; https://github.com/more-itertools/more-itertools/issues/578 py3.5-flask-{0.10,0.11,0.12}: pip install more-itertools<8.11.0 From 3d099446a857cbc6f1042116c642c2a4f54eee1e Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 28 Mar 2022 14:34:41 +0200 Subject: [PATCH 6/6] fix(tests): Fix for Flask not pinning dependencies --- tox.ini | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tox.ini b/tox.ini index a3a46eaa44..bd17e7fe58 100644 --- a/tox.ini +++ b/tox.ini @@ -93,6 +93,9 @@ deps = # with the -r flag -r test-requirements.txt + py3.4: colorama==0.4.1 + py3.4: watchdog==0.10.7 + django-{1.11,2.0,2.1,2.2,3.0,3.1,3.2}: djangorestframework>=3.0.0,<4.0.0 {py3.7,py3.8,py3.9,py3.10}-django-{1.11,2.0,2.1,2.2,3.0,3.1,3.2}: channels>2