From db9cedbcfc76df98b33f9abd071c83cd687ac0b9 Mon Sep 17 00:00:00 2001 From: binaryflesh Date: Wed, 10 Apr 2019 10:13:27 -0500 Subject: [PATCH 1/3] remove deprecated pytest commands Signed-off-by: binaryflesh --- conftest.py | 7 +++++- gitcoin/__init__.py | 5 +--- tests/test_dry_run.py | 54 +++++++++++++++---------------------------- tests/test_live.py | 4 ++-- 4 files changed, 28 insertions(+), 42 deletions(-) diff --git a/conftest.py b/conftest.py index 03b9ab44..8619d336 100644 --- a/conftest.py +++ b/conftest.py @@ -3,4 +3,9 @@ # see https://docs.pytest.org/en/latest/example/simple.html#control-skipping-of-tests-according-to-command-line-option def pytest_addoption(parser): - parser.addoption('--liveapi', action='store_true', default=False, help='run some tests againts live API') + parser.addoption('--liveapi', action='store_true', default=False, help='run some tests against live API') + + +@pytest.fixture +def cmdopt(request): + return request.config.getoption("--liveapi") diff --git a/gitcoin/__init__.py b/gitcoin/__init__.py index a2e794b7..a811d9da 100644 --- a/gitcoin/__init__.py +++ b/gitcoin/__init__.py @@ -1,9 +1,6 @@ """Define the Gitcoin API client.""" -from gitcoin.client import Config -from gitcoin.client import BountyConfig -from gitcoin.client import Endpoint -from gitcoin.client import Gitcoin +from gitcoin.client import BountyConfig, Config, Endpoint, Gitcoin __all__ = [ 'Config', diff --git a/tests/test_dry_run.py b/tests/test_dry_run.py index f1718c46..d1aaaa4d 100644 --- a/tests/test_dry_run.py +++ b/tests/test_dry_run.py @@ -21,7 +21,7 @@ def are_url_queries_equal(url1, url2, *more_urls): return True -class TestGitcoinDryRun(): +class TestGitcoinDryRun(pytest.Collector): def test_are_url_queries_equal(self): assert are_url_queries_equal('https://google.com', 'https://google.com') @@ -48,8 +48,7 @@ def test_api_raises_on_unknown_param(self): with pytest.raises(KeyError): api.bounties.filter(does_not_exist=True) - @responses.activate - def test_all(self): + def test_all(self, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.all() @@ -57,8 +56,7 @@ def test_all(self): assert len(responses.calls) == 1 assert are_url_queries_equal(responses.calls[0].request.url, 'https://gitcoin.co/api/v0.1/bounties/') - @responses.activate - def test_filter_pk__gt(self): + def test_filter_pk__gt(self, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.filter(pk__gt=100).all() @@ -66,8 +64,7 @@ def test_filter_pk__gt(self): assert len(responses.calls) == 1 assert are_url_queries_equal(responses.calls[0].request.url, 'https://gitcoin.co/api/v0.1/bounties/?pk__gt=100') - @responses.activate - def test_filter_experience_level(self): + def test_filter_experience_level(self, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.filter(experience_level='Beginner').all() @@ -79,8 +76,7 @@ def test_filter_experience_level(self): with pytest.raises(ValueError): api.bounties.filter(experience_level='Rockstar') - @responses.activate - def test_filter_project_length(self): + def test_filter_project_length(self, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.filter(project_length='Hours').all() @@ -92,8 +88,7 @@ def test_filter_project_length(self): with pytest.raises(ValueError): api.bounties.filter(project_length='Minutes') - @responses.activate - def test_filter_bounty_type(self): + def test_filter_bounty_type(self, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.filter(bounty_type='Bug').all() @@ -105,8 +100,7 @@ def test_filter_bounty_type(self): with pytest.raises(ValueError): api.bounties.filter(bounty_type='Fancy') - @responses.activate - def test_filter_idx_status(self): + def test_filter_idx_status(self, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.filter(idx_status='started').all() @@ -118,8 +112,7 @@ def test_filter_idx_status(self): with pytest.raises(ValueError): api.bounties.filter(idx_status='undone') - @responses.activate - def test_filter_2x_bounty_type_paged(self): + def test_filter_2x_bounty_type_paged(self, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.filter(bounty_type='Feature').filter(bounty_type='Bug').get_page() @@ -130,21 +123,17 @@ def test_filter_2x_bounty_type_paged(self): 'https://gitcoin.co/api/v0.1/bounties/?bounty_type=Feature%2CBug&offset=0&limit=25' ) - @responses.activate - def test_del_param(self): + def test_del_param(self, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() - result = api.bounties.filter(bounty_type='Feature') \ - ._del_param('bounty_type').filter(bounty_type='Bug').get_page() - assert result == {'mock': 'mock'} + res = api.bounties.filter(bounty_type='Feature')._del_param('bounty_type').filter(bounty_type='Bug').get_page() + assert res == {'mock': 'mock'} assert len(responses.calls) == 1 assert are_url_queries_equal( - responses.calls[0].request.url, - 'https://gitcoin.co/api/v0.1/bounties/?bounty_type=Bug&offset=0&limit=25' + responses.calls[0].request.url, 'https://gitcoin.co/api/v0.1/bounties/?bounty_type=Bug&offset=0&limit=25' ) - @responses.activate - def test_reset_all_params(self): + def test_reset_all_params(self, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() bounties_api = api.bounties @@ -166,8 +155,7 @@ def test_reset_all_params(self): responses.calls[1].request.url, 'https://gitcoin.co/api/v0.1/bounties/?bounty_type=Bug&offset=0&limit=25' ) - @responses.activate - def test_order_by(self): + def test_order_by(self, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() @@ -183,24 +171,21 @@ def test_order_by(self): assert result == {'mock': 'mock'} assert len(responses.calls) == 2 assert are_url_queries_equal( - responses.calls[1].request.url, - 'https://gitcoin.co/api/v0.1/bounties/?order_by=is_open&offset=0&limit=25' + responses.calls[1].request.url, 'https://gitcoin.co/api/v0.1/bounties/?order_by=is_open&offset=0&limit=25' ) with pytest.raises(ValueError): api.bounties.order_by('random') - @responses.activate - def test_get(self): + def test_get(self, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/123', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.get(123) assert result == {'mock': 'mock'} assert len(responses.calls) == 1 - responses.calls[0].request.url == 'https://gitcoin.co/api/v0.1/bounties/123' + assert responses.calls[0].request.url == 'https://gitcoin.co/api/v0.1/bounties/123' - @responses.activate - def test_no_normalize(self): + def test_no_normalize(self, responses): class ExtendedBountyConfig(BountyConfig): @@ -221,8 +206,7 @@ def __init__(self): 'https://gitcoin.co/api/v0.1/bounties/?no_normalize=not_normal&offset=0&limit=25' ) - @responses.activate - def test_raise_for_status(self): + def test_raise_for_status(self, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=401) api = Gitcoin() with pytest.raises(requests.exceptions.HTTPError): diff --git a/tests/test_live.py b/tests/test_live.py index bff337a7..364ed2e9 100644 --- a/tests/test_live.py +++ b/tests/test_live.py @@ -15,10 +15,10 @@ def assert_is_bounty(bounty): @pytest.mark.skipif( - not pytest.config.getoption('--liveapi'), + not pytest.fixture('--liveapi'), reason='Please only test against the live API manually by specifying --live-api.' ) -class TestGitcoinLiveBounties(): +class TestGitcoinLiveBounties(pytest.Generator): filter_examples = { 'experience_level': ['Beginner', 'Advanced', 'Intermediate', 'Unknown'], From 72b88e4c0b92c855d8ea015d41f28cf42738f2fa Mon Sep 17 00:00:00 2001 From: binaryflesh Date: Wed, 10 Apr 2019 10:26:19 -0500 Subject: [PATCH 2/3] remove deprecated pytest commands Signed-off-by: binaryflesh --- conftest.py | 7 +------ tests/test_dry_run.py | 47 ++++++++++++++++++++++++++++--------------- tests/test_live.py | 13 ++++++------ 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/conftest.py b/conftest.py index 8619d336..f66d21fc 100644 --- a/conftest.py +++ b/conftest.py @@ -3,9 +3,4 @@ # see https://docs.pytest.org/en/latest/example/simple.html#control-skipping-of-tests-according-to-command-line-option def pytest_addoption(parser): - parser.addoption('--liveapi', action='store_true', default=False, help='run some tests against live API') - - -@pytest.fixture -def cmdopt(request): - return request.config.getoption("--liveapi") + parser.addoption('--live-api', action='store_true', default=False, help='run some tests against live API') diff --git a/tests/test_dry_run.py b/tests/test_dry_run.py index d1aaaa4d..0a5a5b32 100644 --- a/tests/test_dry_run.py +++ b/tests/test_dry_run.py @@ -6,6 +6,8 @@ import responses from gitcoin import BountyConfig, Gitcoin +pymark = pytest.mark.pytestconfig + def are_url_queries_equal(url1, url2, *more_urls): queries = [] @@ -21,7 +23,7 @@ def are_url_queries_equal(url1, url2, *more_urls): return True -class TestGitcoinDryRun(pytest.Collector): +class TestGitcoinDryRun(): def test_are_url_queries_equal(self): assert are_url_queries_equal('https://google.com', 'https://google.com') @@ -48,7 +50,8 @@ def test_api_raises_on_unknown_param(self): with pytest.raises(KeyError): api.bounties.filter(does_not_exist=True) - def test_all(self, responses): + @classmethod + def test_all(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.all() @@ -56,7 +59,8 @@ def test_all(self, responses): assert len(responses.calls) == 1 assert are_url_queries_equal(responses.calls[0].request.url, 'https://gitcoin.co/api/v0.1/bounties/') - def test_filter_pk__gt(self, responses): + @classmethod + def test_filter_pk__gt(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.filter(pk__gt=100).all() @@ -64,7 +68,8 @@ def test_filter_pk__gt(self, responses): assert len(responses.calls) == 1 assert are_url_queries_equal(responses.calls[0].request.url, 'https://gitcoin.co/api/v0.1/bounties/?pk__gt=100') - def test_filter_experience_level(self, responses): + @classmethod + def test_filter_experience_level(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.filter(experience_level='Beginner').all() @@ -76,7 +81,8 @@ def test_filter_experience_level(self, responses): with pytest.raises(ValueError): api.bounties.filter(experience_level='Rockstar') - def test_filter_project_length(self, responses): + @classmethod + def test_filter_project_length(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.filter(project_length='Hours').all() @@ -88,7 +94,8 @@ def test_filter_project_length(self, responses): with pytest.raises(ValueError): api.bounties.filter(project_length='Minutes') - def test_filter_bounty_type(self, responses): + @classmethod + def test_filter_bounty_type(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.filter(bounty_type='Bug').all() @@ -100,7 +107,8 @@ def test_filter_bounty_type(self, responses): with pytest.raises(ValueError): api.bounties.filter(bounty_type='Fancy') - def test_filter_idx_status(self, responses): + @classmethod + def test_filter_idx_status(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.filter(idx_status='started').all() @@ -112,7 +120,8 @@ def test_filter_idx_status(self, responses): with pytest.raises(ValueError): api.bounties.filter(idx_status='undone') - def test_filter_2x_bounty_type_paged(self, responses): + @classmethod + def test_filter_2x_bounty_type_paged(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.filter(bounty_type='Feature').filter(bounty_type='Bug').get_page() @@ -123,17 +132,19 @@ def test_filter_2x_bounty_type_paged(self, responses): 'https://gitcoin.co/api/v0.1/bounties/?bounty_type=Feature%2CBug&offset=0&limit=25' ) - def test_del_param(self, responses): + @classmethod + def test_del_param(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) - api = Gitcoin() - res = api.bounties.filter(bounty_type='Feature')._del_param('bounty_type').filter(bounty_type='Bug').get_page() + res = Gitcoin().bounties.filter(bounty_type='Feature') + res._del_param('bounty_type').filter(bounty_type='Bug').get_page() assert res == {'mock': 'mock'} assert len(responses.calls) == 1 assert are_url_queries_equal( responses.calls[0].request.url, 'https://gitcoin.co/api/v0.1/bounties/?bounty_type=Bug&offset=0&limit=25' ) - def test_reset_all_params(self, responses): + @classmethod + def test_reset_all_params(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() bounties_api = api.bounties @@ -155,7 +166,8 @@ def test_reset_all_params(self, responses): responses.calls[1].request.url, 'https://gitcoin.co/api/v0.1/bounties/?bounty_type=Bug&offset=0&limit=25' ) - def test_order_by(self, responses): + @classmethod + def test_order_by(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() @@ -177,7 +189,8 @@ def test_order_by(self, responses): with pytest.raises(ValueError): api.bounties.order_by('random') - def test_get(self, responses): + @classmethod + def test_get(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/123', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.get(123) @@ -185,7 +198,8 @@ def test_get(self, responses): assert len(responses.calls) == 1 assert responses.calls[0].request.url == 'https://gitcoin.co/api/v0.1/bounties/123' - def test_no_normalize(self, responses): + @classmethod + def test_no_normalize(cls, responses): class ExtendedBountyConfig(BountyConfig): @@ -206,7 +220,8 @@ def __init__(self): 'https://gitcoin.co/api/v0.1/bounties/?no_normalize=not_normal&offset=0&limit=25' ) - def test_raise_for_status(self, responses): + @classmethod + def test_raise_for_status(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=401) api = Gitcoin() with pytest.raises(requests.exceptions.HTTPError): diff --git a/tests/test_live.py b/tests/test_live.py index 364ed2e9..881c13c5 100644 --- a/tests/test_live.py +++ b/tests/test_live.py @@ -2,6 +2,8 @@ import pytest from gitcoin import BountyConfig, Gitcoin +pytestmark = pytest.mark.liveapi + def assert_is_list_of_bounties(result): assert list == type(result) @@ -10,15 +12,12 @@ def assert_is_list_of_bounties(result): def assert_is_bounty(bounty): - assert isinstance(int, bounty['pk']) - assert bounty['pk'] > 0 + pk = bounty['pk'] + assert isinstance(pk, int) + assert pk > 0 -@pytest.mark.skipif( - not pytest.fixture('--liveapi'), - reason='Please only test against the live API manually by specifying --live-api.' -) -class TestGitcoinLiveBounties(pytest.Generator): +class TestGitcoinLiveBounties(): filter_examples = { 'experience_level': ['Beginner', 'Advanced', 'Intermediate', 'Unknown'], From 9f241eb20bcae149517c255d4982bda37f615c04 Mon Sep 17 00:00:00 2001 From: binaryflesh Date: Wed, 10 Apr 2019 10:13:27 -0500 Subject: [PATCH 3/3] remove deprecated pytest commands Signed-off-by: binaryflesh --- conftest.py | 2 +- gitcoin/__init__.py | 5 +--- tests/test_dry_run.py | 69 +++++++++++++++++++++---------------------- tests/test_live.py | 11 ++++--- 4 files changed, 41 insertions(+), 46 deletions(-) diff --git a/conftest.py b/conftest.py index 03b9ab44..f66d21fc 100644 --- a/conftest.py +++ b/conftest.py @@ -3,4 +3,4 @@ # see https://docs.pytest.org/en/latest/example/simple.html#control-skipping-of-tests-according-to-command-line-option def pytest_addoption(parser): - parser.addoption('--liveapi', action='store_true', default=False, help='run some tests againts live API') + parser.addoption('--live-api', action='store_true', default=False, help='run some tests against live API') diff --git a/gitcoin/__init__.py b/gitcoin/__init__.py index a2e794b7..a811d9da 100644 --- a/gitcoin/__init__.py +++ b/gitcoin/__init__.py @@ -1,9 +1,6 @@ """Define the Gitcoin API client.""" -from gitcoin.client import Config -from gitcoin.client import BountyConfig -from gitcoin.client import Endpoint -from gitcoin.client import Gitcoin +from gitcoin.client import BountyConfig, Config, Endpoint, Gitcoin __all__ = [ 'Config', diff --git a/tests/test_dry_run.py b/tests/test_dry_run.py index f1718c46..0a5a5b32 100644 --- a/tests/test_dry_run.py +++ b/tests/test_dry_run.py @@ -6,6 +6,8 @@ import responses from gitcoin import BountyConfig, Gitcoin +pymark = pytest.mark.pytestconfig + def are_url_queries_equal(url1, url2, *more_urls): queries = [] @@ -48,8 +50,8 @@ def test_api_raises_on_unknown_param(self): with pytest.raises(KeyError): api.bounties.filter(does_not_exist=True) - @responses.activate - def test_all(self): + @classmethod + def test_all(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.all() @@ -57,8 +59,8 @@ def test_all(self): assert len(responses.calls) == 1 assert are_url_queries_equal(responses.calls[0].request.url, 'https://gitcoin.co/api/v0.1/bounties/') - @responses.activate - def test_filter_pk__gt(self): + @classmethod + def test_filter_pk__gt(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.filter(pk__gt=100).all() @@ -66,8 +68,8 @@ def test_filter_pk__gt(self): assert len(responses.calls) == 1 assert are_url_queries_equal(responses.calls[0].request.url, 'https://gitcoin.co/api/v0.1/bounties/?pk__gt=100') - @responses.activate - def test_filter_experience_level(self): + @classmethod + def test_filter_experience_level(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.filter(experience_level='Beginner').all() @@ -79,8 +81,8 @@ def test_filter_experience_level(self): with pytest.raises(ValueError): api.bounties.filter(experience_level='Rockstar') - @responses.activate - def test_filter_project_length(self): + @classmethod + def test_filter_project_length(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.filter(project_length='Hours').all() @@ -92,8 +94,8 @@ def test_filter_project_length(self): with pytest.raises(ValueError): api.bounties.filter(project_length='Minutes') - @responses.activate - def test_filter_bounty_type(self): + @classmethod + def test_filter_bounty_type(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.filter(bounty_type='Bug').all() @@ -105,8 +107,8 @@ def test_filter_bounty_type(self): with pytest.raises(ValueError): api.bounties.filter(bounty_type='Fancy') - @responses.activate - def test_filter_idx_status(self): + @classmethod + def test_filter_idx_status(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.filter(idx_status='started').all() @@ -118,8 +120,8 @@ def test_filter_idx_status(self): with pytest.raises(ValueError): api.bounties.filter(idx_status='undone') - @responses.activate - def test_filter_2x_bounty_type_paged(self): + @classmethod + def test_filter_2x_bounty_type_paged(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.filter(bounty_type='Feature').filter(bounty_type='Bug').get_page() @@ -130,21 +132,19 @@ def test_filter_2x_bounty_type_paged(self): 'https://gitcoin.co/api/v0.1/bounties/?bounty_type=Feature%2CBug&offset=0&limit=25' ) - @responses.activate - def test_del_param(self): + @classmethod + def test_del_param(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) - api = Gitcoin() - result = api.bounties.filter(bounty_type='Feature') \ - ._del_param('bounty_type').filter(bounty_type='Bug').get_page() - assert result == {'mock': 'mock'} + res = Gitcoin().bounties.filter(bounty_type='Feature') + res._del_param('bounty_type').filter(bounty_type='Bug').get_page() + assert res == {'mock': 'mock'} assert len(responses.calls) == 1 assert are_url_queries_equal( - responses.calls[0].request.url, - 'https://gitcoin.co/api/v0.1/bounties/?bounty_type=Bug&offset=0&limit=25' + responses.calls[0].request.url, 'https://gitcoin.co/api/v0.1/bounties/?bounty_type=Bug&offset=0&limit=25' ) - @responses.activate - def test_reset_all_params(self): + @classmethod + def test_reset_all_params(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() bounties_api = api.bounties @@ -166,8 +166,8 @@ def test_reset_all_params(self): responses.calls[1].request.url, 'https://gitcoin.co/api/v0.1/bounties/?bounty_type=Bug&offset=0&limit=25' ) - @responses.activate - def test_order_by(self): + @classmethod + def test_order_by(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=200) api = Gitcoin() @@ -183,24 +183,23 @@ def test_order_by(self): assert result == {'mock': 'mock'} assert len(responses.calls) == 2 assert are_url_queries_equal( - responses.calls[1].request.url, - 'https://gitcoin.co/api/v0.1/bounties/?order_by=is_open&offset=0&limit=25' + responses.calls[1].request.url, 'https://gitcoin.co/api/v0.1/bounties/?order_by=is_open&offset=0&limit=25' ) with pytest.raises(ValueError): api.bounties.order_by('random') - @responses.activate - def test_get(self): + @classmethod + def test_get(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/123', json={'mock': 'mock'}, status=200) api = Gitcoin() result = api.bounties.get(123) assert result == {'mock': 'mock'} assert len(responses.calls) == 1 - responses.calls[0].request.url == 'https://gitcoin.co/api/v0.1/bounties/123' + assert responses.calls[0].request.url == 'https://gitcoin.co/api/v0.1/bounties/123' - @responses.activate - def test_no_normalize(self): + @classmethod + def test_no_normalize(cls, responses): class ExtendedBountyConfig(BountyConfig): @@ -221,8 +220,8 @@ def __init__(self): 'https://gitcoin.co/api/v0.1/bounties/?no_normalize=not_normal&offset=0&limit=25' ) - @responses.activate - def test_raise_for_status(self): + @classmethod + def test_raise_for_status(cls, responses): responses.add(responses.GET, 'https://gitcoin.co/api/v0.1/bounties/', json={'mock': 'mock'}, status=401) api = Gitcoin() with pytest.raises(requests.exceptions.HTTPError): diff --git a/tests/test_live.py b/tests/test_live.py index bff337a7..881c13c5 100644 --- a/tests/test_live.py +++ b/tests/test_live.py @@ -2,6 +2,8 @@ import pytest from gitcoin import BountyConfig, Gitcoin +pytestmark = pytest.mark.liveapi + def assert_is_list_of_bounties(result): assert list == type(result) @@ -10,14 +12,11 @@ def assert_is_list_of_bounties(result): def assert_is_bounty(bounty): - assert isinstance(int, bounty['pk']) - assert bounty['pk'] > 0 + pk = bounty['pk'] + assert isinstance(pk, int) + assert pk > 0 -@pytest.mark.skipif( - not pytest.config.getoption('--liveapi'), - reason='Please only test against the live API manually by specifying --live-api.' -) class TestGitcoinLiveBounties(): filter_examples = {