File tree 3 files changed +30
-4
lines changed
docs/sphinx/source/whatsnew
3 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ Bug fixes
14
14
15
15
Testing
16
16
~~~~~~~
17
+ * Decorator :py:func: `pvlib.conftest.fail_on_pvlib_version ` can now be
18
+ applied to functions that require args or kwargs. (:pull: `973 `)
17
19
18
20
Documentation
19
21
~~~~~~~~~~~~~
Original file line number Diff line number Diff line change 6
6
import pandas as pd
7
7
from pkg_resources import parse_version
8
8
import pytest
9
+ from functools import wraps
9
10
10
11
import pvlib
11
12
16
17
# decorator takes one argument: the base version for which it should fail
17
18
# for example @fail_on_pvlib_version('0.7') will cause a test to fail
18
19
# on pvlib versions 0.7a, 0.7b, 0.7rc1, etc.
19
- # test function may not take args, kwargs, or fixtures.
20
20
def fail_on_pvlib_version (version ):
21
21
# second level of decorator takes the function under consideration
22
22
def wrapper (func ):
23
23
# third level defers computation until the test is called
24
24
# this allows the specific test to fail at test runtime,
25
25
# rather than at decoration time (when the module is imported)
26
- def inner ():
26
+ @wraps (func )
27
+ def inner (* args , ** kwargs ):
27
28
# fail if the version is too high
28
29
if pvlib_base_version >= parse_version (version ):
29
30
pytest .fail ('the tested function is scheduled to be '
30
31
'removed in %s' % version )
31
32
# otherwise return the function to be executed
32
33
else :
33
- return func ()
34
+ return func (* args , ** kwargs )
34
35
return inner
35
36
return wrapper
36
37
37
-
38
38
# commonly used directories in the tests
39
39
TEST_DIR = Path (__file__ ).parent
40
40
DATA_DIR = TEST_DIR .parent / 'data'
Original file line number Diff line number Diff line change 2
2
3
3
from conftest import fail_on_pvlib_version
4
4
5
+ from pvlib ._deprecation import pvlibDeprecationWarning , deprecated
5
6
6
7
@pytest .mark .xfail (strict = True ,
7
8
reason = 'fail_on_pvlib_version should cause test to fail' )
@@ -19,3 +20,26 @@ def test_fail_on_pvlib_version_pass():
19
20
@fail_on_pvlib_version ('100000.0' )
20
21
def test_fail_on_pvlib_version_fail_in_test ():
21
22
raise Exception
23
+
24
+
25
+ # set up to test using fixtures with function decorated with
26
+ # conftest.fail_on_pvlib_version
27
+ @pytest .fixture ()
28
+ def some_data ():
29
+ return "some data"
30
+
31
+
32
+ def alt_func (* args ):
33
+ return args
34
+
35
+
36
+ deprec_func = deprecated ('350.8' , alternative = 'alt_func' ,
37
+ name = 'deprec_func' , removal = '350.9' )(alt_func )
38
+
39
+
40
+ @fail_on_pvlib_version ('350.9' )
41
+ def test_use_fixture_with_decorator (some_data ):
42
+ # test that the correct data is returned by the some_data fixture
43
+ assert some_data == "some data"
44
+ with pytest .warns (pvlibDeprecationWarning ): # test for deprecation warning
45
+ deprec_func (some_data )
You can’t perform that action at this time.
0 commit comments