File tree Expand file tree Collapse file tree 3 files changed +30
-4
lines changed
docs/sphinx/source/whatsnew Expand file tree Collapse file tree 3 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ Bug fixes
1414
1515Testing
1616~~~~~~~
17+ * Decorator :py:func: `pvlib.conftest.fail_on_pvlib_version ` can now be
18+ applied to functions that require args or kwargs. (:pull: `973 `)
1719
1820Documentation
1921~~~~~~~~~~~~~
Original file line number Diff line number Diff line change 66import pandas as pd
77from pkg_resources import parse_version
88import pytest
9+ from functools import wraps
910
1011import pvlib
1112
1617# decorator takes one argument: the base version for which it should fail
1718# for example @fail_on_pvlib_version('0.7') will cause a test to fail
1819# on pvlib versions 0.7a, 0.7b, 0.7rc1, etc.
19- # test function may not take args, kwargs, or fixtures.
2020def fail_on_pvlib_version (version ):
2121 # second level of decorator takes the function under consideration
2222 def wrapper (func ):
2323 # third level defers computation until the test is called
2424 # this allows the specific test to fail at test runtime,
2525 # rather than at decoration time (when the module is imported)
26- def inner ():
26+ @wraps (func )
27+ def inner (* args , ** kwargs ):
2728 # fail if the version is too high
2829 if pvlib_base_version >= parse_version (version ):
2930 pytest .fail ('the tested function is scheduled to be '
3031 'removed in %s' % version )
3132 # otherwise return the function to be executed
3233 else :
33- return func ()
34+ return func (* args , ** kwargs )
3435 return inner
3536 return wrapper
3637
37-
3838# commonly used directories in the tests
3939TEST_DIR = Path (__file__ ).parent
4040DATA_DIR = TEST_DIR .parent / 'data'
Original file line number Diff line number Diff line change 22
33from conftest import fail_on_pvlib_version
44
5+ from pvlib ._deprecation import pvlibDeprecationWarning , deprecated
56
67@pytest .mark .xfail (strict = True ,
78 reason = 'fail_on_pvlib_version should cause test to fail' )
@@ -19,3 +20,26 @@ def test_fail_on_pvlib_version_pass():
1920@fail_on_pvlib_version ('100000.0' )
2021def test_fail_on_pvlib_version_fail_in_test ():
2122 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