Skip to content

Commit 7be246e

Browse files
Use pytest remotedata (#896)
* enable pytest_remotedata for psm3 * add pytest_remotedata to test_pvgis.py * add @pytest.mark.remote_data to other network dependent tests * use up-to-date numpy, pandas * install netcdf4 from pip instead of conda * install pytest-remotedata from pip for conda 3.5 * readd @network to test_midc.py * add pytest-remotedata to py35-min for travis * add to what's new * point coverage at run with --remote-data * add --remote-data to travis run for coveralls to pickup * Revert "point coverage at run with --remote-data" This reverts commit e73eeb0. * Update docs/sphinx/source/whatsnew/v0.7.2.rst Co-Authored-By: Will Holmgren <[email protected]> * Update docs/sphinx/source/whatsnew/v0.7.2.rst Co-Authored-By: Will Holmgren <[email protected]> * Revert "install netcdf4 from pip instead of conda" This reverts commit 6fa8ecf. * fix linelength in what's new * add pytest-remotedata to Azure MacOS * move --remote-data tests to conda_linux * add remote_data decorators to tests requiring network * only install pytest-remotedata from pip, explain * fix tests directory name and url * document use of --remote-data flag in Contributing>Testing Co-authored-by: Will Holmgren <[email protected]>
1 parent 734fbba commit 7be246e

17 files changed

+52
-10
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ install:
6161
- pip install -e .
6262

6363
script:
64-
- pytest pvlib --cov=pvlib --cov-report term-missing
64+
- pytest pvlib --remote-data --cov=pvlib --cov-report term-missing
6565

6666
after_script:
6767
- if [[ $TASK == "coverage" ]]; then

azure-pipelines.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ jobs:
2626
versionSpec: '$(python.version)'
2727

2828
- script: |
29-
pip install pytest pytest-cov pytest-mock pytest-timeout pytest-azurepipelines pytest-rerunfailures
29+
pip install pytest pytest-cov pytest-mock pytest-timeout pytest-azurepipelines pytest-rerunfailures pytest-remotedata
3030
pip install -e .
31-
export NREL_API_KEY=$(nrelApiKey)
3231
pytest pvlib --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
3332
displayName: 'Test with pytest'
3433
@@ -77,7 +76,7 @@ jobs:
7776
- script: |
7877
source activate test_env
7978
export NREL_API_KEY=$(nrelApiKey)
80-
pytest pvlib --junitxml=junit/test-results.xml --cov --cov-report=xml --cov-report=html
79+
pytest pvlib --remote-data --junitxml=junit/test-results.xml --cov --cov-report=xml --cov-report=html
8180
displayName: 'pytest'
8281
# - script: |
8382
# source activate test_env
@@ -129,7 +128,6 @@ jobs:
129128
displayName: 'List installed dependencies'
130129
- script: |
131130
call activate test_env
132-
set NREL_API_KEY=$(nrelApiKey)
133131
pytest pvlib --junitxml=junit/test-results.xml
134132
displayName: 'pytest'
135133
- task: PublishTestResults@2
@@ -157,9 +155,8 @@ jobs:
157155
versionSpec: '$(python.version)'
158156

159157
- script: |
160-
pip install pytest pytest-cov pytest-mock pytest-timeout pytest-azurepipelines pytest-rerunfailures
158+
pip install pytest pytest-cov pytest-mock pytest-timeout pytest-azurepipelines pytest-rerunfailures pytest-remotedata
161159
pip install -e .
162-
export NREL_API_KEY=$(nrelApiKey)
163160
pytest pvlib --junitxml=junit/test-results.xml --cov=pvlib --cov-report=xml --cov-report=html
164161
displayName: 'Test with pytest'
165162

ci/requirements-py35-min.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ dependencies:
1616
- numpy==1.12.0
1717
- pandas==0.18.1
1818
- pytest-rerunfailures # conda version is >3.6
19+
- pytest-remotedata # conda package is 0.3.0, needs > 0.3.1

ci/requirements-py35.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ dependencies:
2727
- nrel-pysam>=2.0
2828
- pvfactors==1.0.1
2929
- pytest-rerunfailures # conda version is >3.6
30+
- pytest-remotedata # needs > 0.3.1

ci/requirements-py36.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies:
1717
- pytest-cov
1818
- pytest-mock
1919
- pytest-rerunfailures
20+
- pytest-remotedata
2021
- pytest-timeout
2122
- python=3.6
2223
- pytz

ci/requirements-py37.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dependencies:
1818
- pytest-mock
1919
- pytest-timeout
2020
- pytest-rerunfailures
21+
- pytest-remotedata
2122
- python=3.7
2223
- pytz
2324
- requests

docs/sphinx/source/contributing.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ Testing
262262
Developers **must** include comprehensive tests for any additions or
263263
modifications to pvlib. New unit test code should be placed in the
264264
corresponding test module in the
265-
`pvlib/test <https://github.com/pvlib/pvlib-python/tree/master/pvlib/test>`_
265+
`pvlib/tests <https://github.com/pvlib/pvlib-python/tree/master/pvlib/tests>`_
266266
directory.
267267

268268
A pull request will automatically run the tests for you on a variety of
@@ -298,6 +298,14 @@ location of a test failure. As described in :ref:`code-style`, pvlib
298298
code does not use ``print`` or ``logging`` calls, and this also applies
299299
to the test suite (with rare exceptions).
300300

301+
To include all network-dependent tests, include the ``--remote-data`` flag to
302+
your ``pytest`` call:
303+
304+
``pytest pvlib --remote-data``
305+
306+
And consider adding ``@pytest.mark.remote_data`` to any network dependent test
307+
you submit for a PR.
308+
301309
pvlib-python contains 3 "layers" of code: functions, PVSystem/Location,
302310
and ModelChain. Contributors will need to add tests that correspond to
303311
the layers that they modify.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ Bug fixes
2525
passing ``tz=datetime.timezone.utc`` (:pull:`879`)
2626
* Fix documentation homepage title to "pvlib python" based on first heading on
2727
the page. (:pull:`890`) (:issue:`888`)
28+
* Implement `pytest-remotedata <https://github.com/astropy/pytest-remotedata>`_
29+
to increase test suite speed. Requires ``--remote-data`` pytest flag to
30+
execute data retrieval tests over a network.
2831
* Fix missing
2932
`0.7.0 what's new <https://pvlib-python.readthedocs.io/en/stable/whatsnew.html#v0-7-0-december-18-2019>`_
3033
entries about changes to ``PVSystem.pvwatts_ac``. Delete unreleased
3134
0.6.4 what's new file. (:issue:`898`)
3235
* Compatibility with cftime 1.1. (:issue:`895`)
3336

37+
3438
Documentation
3539
~~~~~~~~~~~~~
3640
* Add NumFOCUS affiliation to Sphinx documentation :pull:`862`
@@ -47,4 +51,4 @@ Contributors
4751
* Cameron T. Stark (:ghuser:`camerontstark`)
4852
* Will Holmgren (:ghuser:`wholmgren`)
4953
* Kevin Anderson (:ghuser:`kanderso-nrel`)
50-
* Karthikeyan Singaravelan (:ghuser:`tirkarthi`)
54+
* Karthikeyan Singaravelan (:ghuser:`tirkarthi`)

pvlib/tests/iotools/test_epw.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pandas.util.testing import network
2+
import pytest
23

34
from pvlib.iotools import epw
45
from conftest import DATA_DIR
@@ -11,6 +12,7 @@ def test_read_epw():
1112

1213

1314
@network
15+
@pytest.mark.remote_data
1416
def test_read_epw_remote():
1517
url = 'https://energyplus.net/weather-download/europe_wmo_region_6/NLD//NLD_Amsterdam.062400_IWEC/NLD_Amsterdam.062400_IWEC.epw'
1618
epw.read_epw(url)

pvlib/tests/iotools/test_midc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def test_read_midc_var_mapping_as_arg(test_mapping):
6565

6666

6767
@network
68+
@pytest.mark.remote_data
6869
def test_read_midc_raw_data_from_nrel():
6970
start_ts = pd.Timestamp('20181018')
7071
end_ts = pd.Timestamp('20181019')

pvlib/tests/iotools/test_psm3.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def assert_psm3_equal(header, data, expected):
7070
assert (data.index.tzinfo.zone == 'Etc/GMT%+d' % -header['Time Zone'])
7171

7272

73+
@pytest.mark.remote_data
7374
@pytest.mark.flaky(reruns=5, reruns_delay=2)
7475
def test_get_psm3_tmy(nrel_api_key):
7576
"""test get_psm3 with a TMY"""
@@ -79,6 +80,7 @@ def test_get_psm3_tmy(nrel_api_key):
7980
assert_psm3_equal(header, data, expected)
8081

8182

83+
@pytest.mark.remote_data
8284
@pytest.mark.flaky(reruns=5, reruns_delay=2)
8385
def test_get_psm3_singleyear(nrel_api_key):
8486
"""test get_psm3 with a single year"""
@@ -88,6 +90,7 @@ def test_get_psm3_singleyear(nrel_api_key):
8890
assert_psm3_equal(header, data, expected)
8991

9092

93+
@pytest.mark.remote_data
9194
@pytest.mark.flaky(reruns=5, reruns_delay=2)
9295
def test_get_psm3_check_leap_day(nrel_api_key):
9396
_, data_2012 = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key,
@@ -102,6 +105,7 @@ def test_get_psm3_check_leap_day(nrel_api_key):
102105
(LATITUDE, LONGITUDE, nrel_api_key, 'bad', 60),
103106
(LATITUDE, LONGITUDE, nrel_api_key, '2017', 15),
104107
])
108+
@pytest.mark.remote_data
105109
@pytest.mark.flaky(reruns=5, reruns_delay=2)
106110
def test_get_psm3_tmy_errors(
107111
latitude, longitude, api_key, names, interval

pvlib/tests/iotools/test_pvgis.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def csv_meta(meta_expected):
6767
in meta_expected['outputs']['tmy_hourly']['variables'].items()]
6868

6969

70+
@pytest.mark.remote_data
7071
def test_get_pvgis_tmy(expected, month_year_expected, inputs_expected,
7172
meta_expected):
7273
data, months_selected, inputs, meta = get_pvgis_tmy(45, 8)
@@ -92,6 +93,7 @@ def test_get_pvgis_tmy(expected, month_year_expected, inputs_expected,
9293
assert meta == meta_expected
9394

9495

96+
@pytest.mark.remote_data
9597
def test_get_pvgis_tmy_kwargs(userhorizon_expected):
9698
_, _, inputs, _ = get_pvgis_tmy(45, 8, usehorizon=False)
9799
assert inputs['meteo_data']['use_horizon'] is False
@@ -109,13 +111,15 @@ def test_get_pvgis_tmy_kwargs(userhorizon_expected):
109111
assert inputs['meteo_data']['year_max'] == 2016
110112

111113

114+
@pytest.mark.remote_data
112115
def test_get_pvgis_tmy_basic(expected, meta_expected):
113116
data, _, _, _ = get_pvgis_tmy(45, 8, outputformat='basic')
114117
# check each column of output separately
115118
for outvar in meta_expected['outputs']['tmy_hourly']['variables'].keys():
116119
assert np.allclose(data[outvar], expected[outvar])
117120

118121

122+
@pytest.mark.remote_data
119123
def test_get_pvgis_tmy_csv(expected, month_year_expected, inputs_expected,
120124
meta_expected, csv_meta):
121125
data, months_selected, inputs, meta = get_pvgis_tmy(
@@ -138,6 +142,7 @@ def test_get_pvgis_tmy_csv(expected, month_year_expected, inputs_expected,
138142
assert meta_value in csv_meta
139143

140144

145+
@pytest.mark.remote_data
141146
def test_get_pvgis_tmy_epw(expected, epw_meta):
142147
data, _, _, meta = get_pvgis_tmy(
143148
45, 8, outputformat='epw')
@@ -148,6 +153,7 @@ def test_get_pvgis_tmy_epw(expected, epw_meta):
148153
assert meta == epw_meta
149154

150155

156+
@pytest.mark.remote_data
151157
def test_get_pvgis_tmy_error():
152158
err_msg = 'outputformat: Incorrect value.'
153159
with pytest.raises(requests.HTTPError, match=err_msg):

pvlib/tests/iotools/test_srml.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def test_read_srml():
1414

1515

1616
@network
17+
@pytest.mark.remote_data
1718
def test_read_srml_remote():
1819
srml.read_srml('http://solardat.uoregon.edu/download/Archive/EUPO1801.txt')
1920

@@ -40,6 +41,7 @@ def test_read_srml_nans_exist():
4041
('http://solardat.uoregon.edu/download/Archive/EUPO1612.txt',
4142
2016, 12),
4243
])
44+
@pytest.mark.remote_data
4345
def test_read_srml_dt_index(url, year, month):
4446
data = srml.read_srml(url)
4547
start = pd.Timestamp('{:04d}{:02d}01 00:00'.format(year, month))
@@ -63,6 +65,7 @@ def test_map_columns(column, expected):
6365

6466

6567
@network
68+
@pytest.mark.remote_data
6669
def test_read_srml_month_from_solardat():
6770
url = 'http://solardat.uoregon.edu/download/Archive/EUPO1801.txt'
6871
file_data = srml.read_srml(url)
@@ -71,6 +74,7 @@ def test_read_srml_month_from_solardat():
7174

7275

7376
@network
77+
@pytest.mark.remote_data
7478
def test_15_minute_dt_index():
7579
data = srml.read_srml_month_from_solardat('TW', 2019, 4, 'RQ')
7680
start = pd.Timestamp('20190401 00:00')
@@ -83,6 +87,7 @@ def test_15_minute_dt_index():
8387

8488

8589
@network
90+
@pytest.mark.remote_data
8691
def test_hourly_dt_index():
8792
data = srml.read_srml_month_from_solardat('CD', 1986, 4, 'PH')
8893
start = pd.Timestamp('19860401 00:00')

pvlib/tests/iotools/test_surfrad.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pandas as pd
22
from pandas.util.testing import network
3+
import pytest
34

45
from pvlib.iotools import surfrad
56
from conftest import DATA_DIR
@@ -10,6 +11,7 @@
1011

1112

1213
@network
14+
@pytest.mark.remote_data
1315
def test_read_surfrad_network():
1416
# If this test begins failing, SURFRAD's data structure or data
1517
# archive may have changed.

pvlib/tests/iotools/test_tmy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from pandas.util.testing import network
22
import numpy as np
33
import pandas as pd
4+
import pytest
45
from pvlib.iotools import tmy
56
from conftest import DATA_DIR
67

@@ -17,6 +18,7 @@ def test_read_tmy3():
1718

1819

1920
@network
21+
@pytest.mark.remote_data
2022
def test_read_tmy3_remote():
2123
url = 'http://rredc.nrel.gov/solar/old_data/nsrdb/1991-2005/data/tmy3/703165TYA.CSV'
2224
tmy.read_tmy3(url)

pvlib/tests/test_forecast.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def model(request):
5959

6060

6161
@requires_siphon
62+
@pytest.mark.remote_data
6263
def test_process_data(model):
6364
for how in ['liujordan', 'clearsky_scaling']:
6465
if model.raw_data.empty:
@@ -75,6 +76,7 @@ def test_process_data(model):
7576

7677

7778
@requires_siphon
79+
@pytest.mark.remote_data
7880
def test_bad_kwarg_get_data():
7981
# For more information on why you would want to pass an unknown keyword
8082
# argument, see Github issue #745.
@@ -85,6 +87,7 @@ def test_bad_kwarg_get_data():
8587

8688

8789
@requires_siphon
90+
@pytest.mark.remote_data
8891
def test_bad_kwarg_get_processed_data():
8992
# For more information on why you would want to pass an unknown keyword
9093
# argument, see Github issue #745.
@@ -95,6 +98,7 @@ def test_bad_kwarg_get_processed_data():
9598

9699

97100
@requires_siphon
101+
@pytest.mark.remote_data
98102
def test_how_kwarg_get_processed_data():
99103
amodel = NAM()
100104
data = amodel.get_processed_data(_latitude, _longitude, _start, _end,
@@ -103,6 +107,7 @@ def test_how_kwarg_get_processed_data():
103107

104108

105109
@requires_siphon
110+
@pytest.mark.remote_data
106111
def test_vert_level():
107112
amodel = NAM()
108113
vert_level = 5000
@@ -111,6 +116,7 @@ def test_vert_level():
111116

112117

113118
@requires_siphon
119+
@pytest.mark.remote_data
114120
def test_datetime():
115121
amodel = NAM()
116122
start = datetime.now(tz=timezone.utc)
@@ -119,6 +125,7 @@ def test_datetime():
119125

120126

121127
@requires_siphon
128+
@pytest.mark.remote_data
122129
def test_queryvariables():
123130
amodel = GFS()
124131
new_variables = ['u-component_of_wind_height_above_ground']

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
'pytz',
4343
'requests']
4444
TESTS_REQUIRE = ['nose', 'pytest', 'pytest-cov', 'pytest-mock',
45-
'pytest-timeout', 'pytest-rerunfailures']
45+
'pytest-timeout', 'pytest-rerunfailures', 'pytest-remotedata']
4646
EXTRAS_REQUIRE = {
4747
'optional': ['ephem', 'cython', 'netcdf4', 'nrel-pysam', 'numba',
4848
'pvfactors', 'scipy', 'siphon', 'tables'],

0 commit comments

Comments
 (0)