Skip to content

Commit 26ec9a7

Browse files
committed
Cleaning up usage of old pytest
1 parent 0833f63 commit 26ec9a7

File tree

36 files changed

+113
-226
lines changed

36 files changed

+113
-226
lines changed

astroquery/alfalfa/tests/test_alfalfa.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ def close(self):
2727

2828
@pytest.fixture
2929
def patch_get(request):
30-
try:
31-
mp = request.getfixturevalue("monkeypatch")
32-
except AttributeError: # pytest < 3
33-
mp = request.getfuncargvalue("monkeypatch")
30+
mp = request.getfixturevalue("monkeypatch")
31+
3432
mp.setattr(requests, 'get', get_mockreturn)
3533
return mp
3634

@@ -41,10 +39,9 @@ def patch_get_readable_fileobj(request):
4139
def get_readable_fileobj_mockreturn(filename, **kwargs):
4240
file_obj = data_path(DATA_FILES['spectrum']) # TODO: add images option
4341
yield open(file_obj, 'rb') # read as bytes, assuming FITS
44-
try:
45-
mp = request.getfixturevalue("monkeypatch")
46-
except AttributeError: # pytest < 3
47-
mp = request.getfuncargvalue("monkeypatch")
42+
43+
mp = request.getfixturevalue("monkeypatch")
44+
4845
mp.setattr(commons, 'get_readable_fileobj',
4946
get_readable_fileobj_mockreturn)
5047
return mp

astroquery/astrometry_net/tests/test_astrometry_net.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22
import os
33
import json
4-
from distutils.version import LooseVersion
54

65
import pytest
76

8-
from ...utils.testing_tools import MockResponse
9-
from ...exceptions import (InvalidQueryError)
10-
117
from .. import AstrometryNet
128

13-
_pytest_is_old = LooseVersion(pytest.__version__) < LooseVersion('3.3')
14-
159
DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
1610

1711

1812
def data_path(filename):
1913
return os.path.join(DATA_DIR, filename)
2014

2115

22-
@pytest.mark.skipif(_pytest_is_old,
23-
reason='pytest version too old for caplog')
2416
def test_api_key_property(caplog):
2517
"""
2618
Check that an empty key is returned if the api key is not in
@@ -46,8 +38,6 @@ def test_empty_settings_property():
4638
assert set(empty.keys()) == set(anet._constraints.keys())
4739

4840

49-
@pytest.mark.skipif(_pytest_is_old,
50-
reason='pytest version too old for output attributes')
5141
def test_show_allowed_settings(capsys):
5242
"""
5343
Check that the expected content is printed to standard out when the

astroquery/besancon/tests/test_besancon.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@ def test_reader(filename, length, ncols, d1, mv1):
5252

5353
@pytest.fixture
5454
def patch_post(request):
55-
try:
56-
mp = request.getfixturevalue("monkeypatch")
57-
except AttributeError: # pytest < 3
58-
mp = request.getfuncargvalue("monkeypatch")
55+
mp = request.getfixturevalue("monkeypatch")
56+
5957
mp.setattr(besancon.Besancon, '_request', post_mockreturn)
6058
return mp
6159

@@ -72,10 +70,9 @@ def get_readable_fileobj_mockreturn(filename, **kwargs):
7270
else:
7371
file_obj = filename
7472
yield file_obj
75-
try:
76-
mp = request.getfixturevalue("monkeypatch")
77-
except AttributeError: # pytest < 3
78-
mp = request.getfuncargvalue("monkeypatch")
73+
74+
mp = request.getfixturevalue("monkeypatch")
75+
7976
mp.setattr(commons, 'get_readable_fileobj',
8077
get_readable_fileobj_mockreturn)
8178
return mp

astroquery/casda/tests/test_casda.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from astroquery.casda import Casda
1717

1818
try:
19-
from unittest.mock import Mock, patch, PropertyMock, MagicMock
19+
from unittest.mock import Mock, patch, MagicMock
2020
except ImportError:
2121
pytest.skip("Install mock for the casda tests.", allow_module_level=True)
2222

@@ -94,10 +94,8 @@ def create_auth_failure_response():
9494

9595
@pytest.fixture
9696
def patch_get(request):
97-
try:
98-
mp = request.getfixturevalue("monkeypatch")
99-
except AttributeError: # pytest < 3
100-
mp = request.getfuncargvalue("monkeypatch")
97+
mp = request.getfixturevalue("monkeypatch")
98+
10199
mp.setattr(requests.Session, 'request', get_mockreturn)
102100
return mp
103101

astroquery/cds/tests/test_mocserver.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*
22

33
# Licensed under a 3-clause BSD style license - see LICENSE.rst
4-
import sys
54
import pytest
65
import os
76
import requests
@@ -33,10 +32,8 @@
3332

3433
@pytest.fixture
3534
def patch_get(request):
36-
try:
37-
mp = request.getfixturevalue("monkeypatch")
38-
except AttributeError: # pytest < 3
39-
mp = request.getfuncargvalue("monkeypatch")
35+
mp = request.getfixturevalue("monkeypatch")
36+
4037
mp.setattr(requests.Session, 'request', get_mockreturn)
4138
return mp
4239

astroquery/eso/tests/test_eso.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ def eso_request(request_type, url, **kwargs):
3636

3737
# @pytest.fixture
3838
# def patch_get(request):
39-
# try:
40-
# mp = request.getfixturevalue("monkeypatch")
41-
# except AttributeError: # pytest < 3
42-
# mp = request.getfuncargvalue("monkeypatch")
39+
# mp = request.getfixturevalue("monkeypatch")
40+
#
4341
# mp.setattr(Eso, 'request', eso_request)
4442
# return mp
4543

astroquery/fermi/tests/test_fermi.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ def data_path(filename):
2121

2222
@pytest.fixture
2323
def patch_post(request):
24-
try:
25-
mp = request.getfixturevalue("monkeypatch")
26-
except AttributeError: # pytest < 3
27-
mp = request.getfuncargvalue("monkeypatch")
24+
mp = request.getfixturevalue("monkeypatch")
25+
2826
mp.setattr(fermi.FermiLAT, '_request', post_mockreturn)
2927
mp.setattr(requests, 'post', post_mockreturn)
3028
return mp

astroquery/gemini/tests/test_gemini.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ def json(self):
3232
@pytest.fixture
3333
def patch_get(request):
3434
""" mock get requests so they return our canned JSON to mimic Gemini's archive website """
35-
try:
36-
mp = request.getfixturevalue("monkeypatch")
37-
except AttributeError: # pytest < 3
38-
mp = request.getfuncargvalue("monkeypatch")
35+
mp = request.getfixturevalue("monkeypatch")
36+
3937
mp.setattr(requests.Session, 'request', get_mockreturn)
4038
return mp
4139

astroquery/imcce/tests/test_miriade.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22

3-
43
import pytest
54
import os
65

@@ -32,12 +31,9 @@ def nonremote_request(self, request_type, url, **kwargs):
3231
# that mocks(monkeypatches) the actual 'requests.get' function:
3332
@pytest.fixture
3433
def patch_request(request):
35-
try:
36-
mp = request.getfixturevalue("monkeypatch")
37-
except AttributeError: # pytest < 3
38-
mp = request.getfuncargvalue("monkeypatch")
39-
mp.setattr(MiriadeClass, '_request',
40-
nonremote_request)
34+
mp = request.getfixturevalue("monkeypatch")
35+
36+
mp.setattr(MiriadeClass, '_request', nonremote_request)
4137
return mp
4238

4339

astroquery/imcce/tests/test_skybot.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ def nonremote_request(self, url, **kwargs):
3232
# that mocks(monkeypatches) the actual 'requests.get' function:
3333
@pytest.fixture
3434
def patch_request(request):
35-
try:
36-
mp = request.getfixturevalue("monkeypatch")
37-
except AttributeError: # pytest < 3
38-
mp = request.getfuncargvalue("monkeypatch")
39-
mp.setattr(SkybotClass, '_request',
40-
nonremote_request)
35+
mp = request.getfixturevalue("monkeypatch")
36+
37+
mp.setattr(SkybotClass, '_request', nonremote_request)
4138
return mp
4239

4340

0 commit comments

Comments
 (0)