Skip to content

Commit 94471fd

Browse files
TST: make iotools tests robust to API downtime (#919)
* add pytest.mark.flaky() to remote_data() * move CI in what's new to Testing section * add to what's new * use RERUNS, RERUNS_DELAY variables to set flaky calls * add imports to test_pvgis.py, punctuation
1 parent d6b85c1 commit 94471fd

File tree

10 files changed

+48
-19
lines changed

10 files changed

+48
-19
lines changed

docs/sphinx/source/whatsnew/v0.7.2.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Enhancements
1616
* TMY3 dataframe returned by :py:func:`~pvlib.iotools.read_tmy3` now contains
1717
the original ``Date (MM/DD/YYYY)`` and ``Time (HH:MM)`` columns that the
1818
indices were parsed from. (:pull:`866`)
19-
* Add :py:func:`~pvlib.pvsystem.PVSystem.faiman` and added
19+
* Add :py:func:`~pvlib.pvsystem.PVSystem.faiman` and added
2020
``temperature_model='faiman'`` option to :py:class:`~pvlib.modelchain.ModelChain`
2121
(:pull:`897`) (:issue:`836`).
2222
* Add Kimber soiling model :py:func:`pvlib.losses.soiling_kimber`. (:pull:`860`)
@@ -33,16 +33,11 @@ Bug fixes
3333
passing ``tz=datetime.timezone.utc``. (:pull:`879`)
3434
* Fix documentation homepage title to "pvlib python" based on first heading on
3535
the page. (:pull:`890`) (:issue:`888`)
36-
* Implement `pytest-remotedata <https://github.com/astropy/pytest-remotedata>`_
37-
to increase test suite speed. Requires ``--remote-data`` pytest flag to
38-
execute data retrieval tests over a network. (:issue:`882`)(:pull:`896`)
3936
* Fix missing
4037
`0.7.0 what's new <https://pvlib-python.readthedocs.io/en/stable/whatsnew.html#v0-7-0-december-18-2019>`_
4138
entries about changes to ``PVSystem.pvwatts_ac``. Delete unreleased
4239
0.6.4 what's new file. (:issue:`898`)
4340
* Compatibility with cftime 1.1. (:issue:`895`)
44-
* Add Python3.8 to Azure Pipelines CI. (:issue:`903`)(:pull:`904`)
45-
* Add documentation build test to Azure Pipelines CI. (:pull:`909`)
4641
* Minor implemention changes to avoid runtime and deprecation warnings in
4742
:py:func:`~pvlib.clearsky.detect_clearsky`,
4843
:py:func:`~pvlib.iam.martin_ruiz_diffuse`,
@@ -55,6 +50,14 @@ Testing
5550
~~~~~~~
5651
* Rename `system` fixture to `sapm_dc_snl_ac_system` in model chain
5752
tests. (:issue:`908`, :pull:`915`).
53+
* Implement `pytest-remotedata <https://github.com/astropy/pytest-remotedata>`_
54+
to increase test suite speed. Requires ``--remote-data`` pytest flag to
55+
execute data retrieval tests over a network. (:issue:`882`)(:pull:`896`)
56+
* Add Python3.8 to Azure Pipelines CI. (:issue:`903`)(:pull:`904`)
57+
* Add documentation build test to Azure Pipelines CI. (:pull:`909`)
58+
* Implement the `pytest.mark.flaky` decorator from `pytest-rurunfailures`
59+
`<https://github.com/pytest-dev/pytest-rerunfailures>`_ on all network
60+
dependent iotools tests to repeat them on failure. (:pull:`919`)
5861

5962
Documentation
6063
~~~~~~~~~~~~~

pvlib/tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ def inner():
4040
DATA_DIR = TEST_DIR.parent / 'data'
4141

4242

43+
# pytest-rerunfailures variables
44+
RERUNS = 5
45+
RERUNS_DELAY = 2
46+
47+
4348
platform_is_windows = platform.system() == 'Windows'
4449
skip_windows = pytest.mark.skipif(platform_is_windows,
4550
reason='does not run on windows')

pvlib/tests/iotools/test_epw.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pytest
33

44
from pvlib.iotools import epw
5-
from conftest import DATA_DIR
5+
from conftest import DATA_DIR, RERUNS, RERUNS_DELAY
66

77
epw_testfile = DATA_DIR / 'NLD_Amsterdam062400_IWEC.epw'
88

@@ -13,6 +13,7 @@ def test_read_epw():
1313

1414
@network
1515
@pytest.mark.remote_data
16+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
1617
def test_read_epw_remote():
1718
url = 'https://energyplus.net/weather-download/europe_wmo_region_6/NLD//NLD_Amsterdam.062400_IWEC/NLD_Amsterdam.062400_IWEC.epw'
1819
epw.read_epw(url)

pvlib/tests/iotools/test_midc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytz
55

66
from pvlib.iotools import midc
7-
from conftest import DATA_DIR
7+
from conftest import DATA_DIR, RERUNS, RERUNS_DELAY
88

99

1010
@pytest.fixture
@@ -66,6 +66,7 @@ def test_read_midc_var_mapping_as_arg(test_mapping):
6666

6767
@network
6868
@pytest.mark.remote_data
69+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
6970
def test_read_midc_raw_data_from_nrel():
7071
start_ts = pd.Timestamp('20181018')
7172
end_ts = pd.Timestamp('20181019')

pvlib/tests/iotools/test_psm3.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import os
66
from pvlib.iotools import psm3
7-
from conftest import DATA_DIR
7+
from conftest import DATA_DIR, RERUNS, RERUNS_DELAY
88
import numpy as np
99
import pandas as pd
1010
import pytest
@@ -71,7 +71,7 @@ def assert_psm3_equal(header, data, expected):
7171

7272

7373
@pytest.mark.remote_data
74-
@pytest.mark.flaky(reruns=5, reruns_delay=2)
74+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
7575
def test_get_psm3_tmy(nrel_api_key):
7676
"""test get_psm3 with a TMY"""
7777
header, data = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key,
@@ -81,7 +81,7 @@ def test_get_psm3_tmy(nrel_api_key):
8181

8282

8383
@pytest.mark.remote_data
84-
@pytest.mark.flaky(reruns=5, reruns_delay=2)
84+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
8585
def test_get_psm3_singleyear(nrel_api_key):
8686
"""test get_psm3 with a single year"""
8787
header, data = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key,
@@ -91,7 +91,7 @@ def test_get_psm3_singleyear(nrel_api_key):
9191

9292

9393
@pytest.mark.remote_data
94-
@pytest.mark.flaky(reruns=5, reruns_delay=2)
94+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
9595
def test_get_psm3_check_leap_day(nrel_api_key):
9696
_, data_2012 = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key,
9797
PVLIB_EMAIL, names="2012", interval=60,
@@ -106,7 +106,7 @@ def test_get_psm3_check_leap_day(nrel_api_key):
106106
(LATITUDE, LONGITUDE, nrel_api_key, '2017', 15),
107107
])
108108
@pytest.mark.remote_data
109-
@pytest.mark.flaky(reruns=5, reruns_delay=2)
109+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
110110
def test_get_psm3_tmy_errors(
111111
latitude, longitude, api_key, names, interval
112112
):

pvlib/tests/iotools/test_pvgis.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
import pytest
88
import requests
99
from pvlib.iotools import get_pvgis_tmy, read_pvgis_tmy
10-
from conftest import DATA_DIR
11-
10+
from conftest import DATA_DIR, RERUNS, RERUNS_DELAY
1211

1312
@pytest.fixture
1413
def expected():
@@ -68,6 +67,7 @@ def csv_meta(meta_expected):
6867

6968

7069
@pytest.mark.remote_data
70+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
7171
def test_get_pvgis_tmy(expected, month_year_expected, inputs_expected,
7272
meta_expected):
7373
pvgis_data = get_pvgis_tmy(45, 8)
@@ -101,6 +101,7 @@ def _compare_pvgis_tmy_json(expected, month_year_expected, inputs_expected,
101101

102102

103103
@pytest.mark.remote_data
104+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
104105
def test_get_pvgis_tmy_kwargs(userhorizon_expected):
105106
_, _, inputs, _ = get_pvgis_tmy(45, 8, usehorizon=False)
106107
assert inputs['meteo_data']['use_horizon'] is False
@@ -119,6 +120,7 @@ def test_get_pvgis_tmy_kwargs(userhorizon_expected):
119120

120121

121122
@pytest.mark.remote_data
123+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
122124
def test_get_pvgis_tmy_basic(expected, meta_expected):
123125
pvgis_data = get_pvgis_tmy(45, 8, outputformat='basic')
124126
_compare_pvgis_tmy_basic(expected, meta_expected, pvgis_data)
@@ -132,6 +134,7 @@ def _compare_pvgis_tmy_basic(expected, meta_expected, pvgis_data):
132134

133135

134136
@pytest.mark.remote_data
137+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
135138
def test_get_pvgis_tmy_csv(expected, month_year_expected, inputs_expected,
136139
meta_expected, csv_meta):
137140
pvgis_data = get_pvgis_tmy(45, 8, outputformat='csv')
@@ -161,6 +164,7 @@ def _compare_pvgis_tmy_csv(expected, month_year_expected, inputs_expected,
161164

162165

163166
@pytest.mark.remote_data
167+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
164168
def test_get_pvgis_tmy_epw(expected, epw_meta):
165169
pvgis_data = get_pvgis_tmy(45, 8, outputformat='epw')
166170
_compare_pvgis_tmy_epw(expected, epw_meta, pvgis_data)
@@ -176,6 +180,7 @@ def _compare_pvgis_tmy_epw(expected, epw_meta, pvgis_data):
176180

177181

178182
@pytest.mark.remote_data
183+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
179184
def test_get_pvgis_tmy_error():
180185
err_msg = 'outputformat: Incorrect value.'
181186
with pytest.raises(requests.HTTPError, match=err_msg):

pvlib/tests/iotools/test_srml.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55

66
from pvlib.iotools import srml
7-
from conftest import DATA_DIR
7+
from conftest import DATA_DIR, RERUNS, RERUNS_DELAY
88

99
srml_testfile = DATA_DIR / 'SRML-day-EUPO1801.txt'
1010

@@ -15,6 +15,7 @@ def test_read_srml():
1515

1616
@network
1717
@pytest.mark.remote_data
18+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
1819
def test_read_srml_remote():
1920
srml.read_srml('http://solardat.uoregon.edu/download/Archive/EUPO1801.txt')
2021

@@ -42,6 +43,7 @@ def test_read_srml_nans_exist():
4243
2016, 12),
4344
])
4445
@pytest.mark.remote_data
46+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
4547
def test_read_srml_dt_index(url, year, month):
4648
data = srml.read_srml(url)
4749
start = pd.Timestamp('{:04d}{:02d}01 00:00'.format(year, month))
@@ -66,6 +68,7 @@ def test_map_columns(column, expected):
6668

6769
@network
6870
@pytest.mark.remote_data
71+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
6972
def test_read_srml_month_from_solardat():
7073
url = 'http://solardat.uoregon.edu/download/Archive/EUPO1801.txt'
7174
file_data = srml.read_srml(url)
@@ -75,6 +78,7 @@ def test_read_srml_month_from_solardat():
7578

7679
@network
7780
@pytest.mark.remote_data
81+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
7882
def test_15_minute_dt_index():
7983
data = srml.read_srml_month_from_solardat('TW', 2019, 4, 'RQ')
8084
start = pd.Timestamp('20190401 00:00')
@@ -88,6 +92,7 @@ def test_15_minute_dt_index():
8892

8993
@network
9094
@pytest.mark.remote_data
95+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
9196
def test_hourly_dt_index():
9297
data = srml.read_srml_month_from_solardat('CD', 1986, 4, 'PH')
9398
start = pd.Timestamp('19860401 00:00')

pvlib/tests/iotools/test_surfrad.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44

55
from pvlib.iotools import surfrad
6-
from conftest import DATA_DIR
6+
from conftest import DATA_DIR, RERUNS, RERUNS_DELAY
77

88
testfile = DATA_DIR / 'surfrad-slv16001.dat'
99
network_testfile = ('ftp://aftp.cmdl.noaa.gov/data/radiation/surfrad/'
@@ -12,6 +12,7 @@
1212

1313
@network
1414
@pytest.mark.remote_data
15+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
1516
def test_read_surfrad_network():
1617
# If this test begins failing, SURFRAD's data structure or data
1718
# archive may have changed.

pvlib/tests/iotools/test_tmy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import pandas as pd
44
import pytest
55
from pvlib.iotools import tmy
6-
from pvlib.iotools import read_tmy3
7-
from conftest import DATA_DIR
6+
from conftest import DATA_DIR, RERUNS, RERUNS_DELAY
87

98
# test the API works
109
from pvlib.iotools import read_tmy3
@@ -20,6 +19,7 @@ def test_read_tmy3():
2019

2120
@network
2221
@pytest.mark.remote_data
22+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
2323
def test_read_tmy3_remote():
2424
url = 'http://rredc.nrel.gov/solar/old_data/nsrdb/1991-2005/data/tmy3/703165TYA.CSV'
2525
tmy.read_tmy3(url)

pvlib/tests/test_forecast.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from numpy.testing import assert_allclose
88

99
from conftest import requires_siphon, has_siphon, skip_windows
10+
from conftest import RERUNS, RERUNS_DELAY
1011

1112
pytestmark = pytest.mark.skipif(not has_siphon, reason='requires siphon')
1213

@@ -60,6 +61,7 @@ def model(request):
6061

6162
@requires_siphon
6263
@pytest.mark.remote_data
64+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
6365
def test_process_data(model):
6466
for how in ['liujordan', 'clearsky_scaling']:
6567
if model.raw_data.empty:
@@ -77,6 +79,7 @@ def test_process_data(model):
7779

7880
@requires_siphon
7981
@pytest.mark.remote_data
82+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
8083
def test_bad_kwarg_get_data():
8184
# For more information on why you would want to pass an unknown keyword
8285
# argument, see Github issue #745.
@@ -88,6 +91,7 @@ def test_bad_kwarg_get_data():
8891

8992
@requires_siphon
9093
@pytest.mark.remote_data
94+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
9195
def test_bad_kwarg_get_processed_data():
9296
# For more information on why you would want to pass an unknown keyword
9397
# argument, see Github issue #745.
@@ -99,6 +103,7 @@ def test_bad_kwarg_get_processed_data():
99103

100104
@requires_siphon
101105
@pytest.mark.remote_data
106+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
102107
def test_how_kwarg_get_processed_data():
103108
amodel = NAM()
104109
data = amodel.get_processed_data(_latitude, _longitude, _start, _end,
@@ -108,6 +113,7 @@ def test_how_kwarg_get_processed_data():
108113

109114
@requires_siphon
110115
@pytest.mark.remote_data
116+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
111117
def test_vert_level():
112118
amodel = NAM()
113119
vert_level = 5000
@@ -117,6 +123,7 @@ def test_vert_level():
117123

118124
@requires_siphon
119125
@pytest.mark.remote_data
126+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
120127
def test_datetime():
121128
amodel = NAM()
122129
start = datetime.now(tz=timezone.utc)
@@ -126,6 +133,7 @@ def test_datetime():
126133

127134
@requires_siphon
128135
@pytest.mark.remote_data
136+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
129137
def test_queryvariables():
130138
amodel = GFS()
131139
new_variables = ['u-component_of_wind_height_above_ground']

0 commit comments

Comments
 (0)