Skip to content

Commit cabe2fc

Browse files
committed
move nrel api key fixture to conftest
1 parent 502b323 commit cabe2fc

3 files changed

Lines changed: 26 additions & 47 deletions

File tree

pvlib/tests/conftest.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,26 @@ def assert_frame_equal(left, right, **kwargs):
8383
reason='does not run on windows')
8484

8585

86+
@pytest.fixture(scope="module")
87+
def nrel_api_key():
88+
"""Supplies pvlib-python's NREL Developer Network API key.
89+
90+
Azure Pipelines CI utilizes a secret variable set to NREL_API_KEY
91+
to mitigate failures associated with using the default key of
92+
"DEMO_KEY". A user is capable of using their own key this way if
93+
desired however the default key should suffice for testing purposes.
94+
"""
95+
try:
96+
demo_key = os.environ["NREL_API_KEY"]
97+
except KeyError:
98+
warnings.warn(
99+
"WARNING: NREL API KEY environment variable not set! "
100+
"Using DEMO_KEY instead. Unexpected failures may occur."
101+
)
102+
demo_key = 'DEMO_KEY'
103+
return demo_key
104+
105+
86106
try:
87107
# Attempt to load BSRN credentials used for testing pvlib.iotools.get_bsrn
88108
bsrn_username = os.environ["BSRN_FTP_USERNAME"]

pvlib/tests/iotools/test_psm3.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
test iotools for PSM3
33
"""
44

5-
import os
65
from pvlib.iotools import psm3
7-
from ..conftest import DATA_DIR, RERUNS, RERUNS_DELAY, assert_index_equal
6+
from ..conftest import (
7+
DATA_DIR, RERUNS, RERUNS_DELAY, assert_index_equal, nrel_api_key
8+
)
89
import numpy as np
910
import pandas as pd
1011
import pytest
1112
from requests import HTTPError
1213
from io import StringIO
13-
import warnings
14-
from pvlib._deprecation import pvlibDeprecationWarning
1514

1615
TMY_TEST_DATA = DATA_DIR / 'test_psm3_tmy-2017.csv'
1716
YEAR_TEST_DATA = DATA_DIR / 'test_psm3_2017.csv'
@@ -27,26 +26,6 @@
2726
PVLIB_EMAIL = 'pvlib-admin@googlegroups.com'
2827

2928

30-
@pytest.fixture(scope="module")
31-
def nrel_api_key():
32-
"""Supplies pvlib-python's NREL Developer Network API key.
33-
34-
Azure Pipelines CI utilizes a secret variable set to NREL_API_KEY
35-
to mitigate failures associated with using the default key of
36-
"DEMO_KEY". A user is capable of using their own key this way if
37-
desired however the default key should suffice for testing purposes.
38-
"""
39-
try:
40-
demo_key = os.environ["NREL_API_KEY"]
41-
except KeyError:
42-
warnings.warn(
43-
"WARNING: NREL API KEY environment variable not set! "
44-
"Using DEMO_KEY instead. Unexpected failures may occur."
45-
)
46-
demo_key = 'DEMO_KEY'
47-
return demo_key
48-
49-
5029
def assert_psm3_equal(data, metadata, expected):
5130
"""check consistency of PSM3 data"""
5231
# check datevec columns

pvlib/tests/iotools/test_psm4.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
test iotools for PSM4
33
"""
44

5-
import os
65
from pvlib.iotools import psm4
7-
from ..conftest import DATA_DIR, RERUNS, RERUNS_DELAY, assert_index_equal
6+
from ..conftest import (
7+
DATA_DIR, RERUNS, RERUNS_DELAY, assert_index_equal, nrel_api_key
8+
)
89
import numpy as np
910
import pandas as pd
1011
import pytest
1112
from requests import HTTPError
1213
from io import StringIO
13-
import warnings
1414

1515
TMY_TEST_DATA = DATA_DIR / 'test_psm4_tmy-2023.csv'
1616
YEAR_TEST_DATA = DATA_DIR / 'test_psm4_2023.csv'
@@ -26,26 +26,6 @@
2626
PVLIB_EMAIL = 'pvlib-admin@googlegroups.com'
2727

2828

29-
@pytest.fixture(scope="module")
30-
def nrel_api_key():
31-
"""Supplies pvlib-python's NREL Developer Network API key.
32-
33-
Azure Pipelines CI utilizes a secret variable set to NREL_API_KEY
34-
to mitigate failures associated with using the default key of
35-
"DEMO_KEY". A user is capable of using their own key this way if
36-
desired however the default key should suffice for testing purposes.
37-
"""
38-
try:
39-
demo_key = os.environ["NREL_API_KEY"]
40-
except KeyError:
41-
warnings.warn(
42-
"WARNING: NREL API KEY environment variable not set! "
43-
"Using DEMO_KEY instead. Unexpected failures may occur."
44-
)
45-
demo_key = 'DEMO_KEY'
46-
return demo_key
47-
48-
4929
def assert_psm4_equal(data, metadata, expected):
5030
"""check consistency of PSM4 data"""
5131
# check datevec columns

0 commit comments

Comments
 (0)