diff --git a/docs/sphinx/source/whatsnew/v0.11.2.rst b/docs/sphinx/source/whatsnew/v0.11.2.rst index 81d36fda64..aa713babac 100644 --- a/docs/sphinx/source/whatsnew/v0.11.2.rst +++ b/docs/sphinx/source/whatsnew/v0.11.2.rst @@ -27,8 +27,15 @@ Requirements ~~~~~~~~~~~~ +Maintenance +~~~~~~~~~~~ +* Added a decorator to deprecate renamed keyword arguments in functions, + :py:func:`pvlib._deprecation.renamed_kwarg_warning`. (:pull:`2237`) + + Contributors ~~~~~~~~~~~~ * Cliff Hansen (:ghuser:`cwhanse`) * Rajiv Daxini (:ghuser:`RDaxini`) +* Echedey Luis (:ghuser:`echedey-ls`) diff --git a/pvlib/tests/test__deprecation.py b/pvlib/tests/test__deprecation.py index 177082ca9d..31263c8a25 100644 --- a/pvlib/tests/test__deprecation.py +++ b/pvlib/tests/test__deprecation.py @@ -5,10 +5,56 @@ import pytest from pvlib import _deprecation +from .conftest import fail_on_pvlib_version import warnings +@pytest.mark.xfail(strict=True, + reason='fail_on_pvlib_version should cause test to fail') +@fail_on_pvlib_version('0.0') +def test_fail_on_pvlib_version(): + pass # pragma: no cover + + +@fail_on_pvlib_version('100000.0') +def test_fail_on_pvlib_version_pass(): + pass + + +@pytest.mark.xfail(strict=True, reason='ensure that the test is called') +@fail_on_pvlib_version('100000.0') +def test_fail_on_pvlib_version_fail_in_test(): + raise Exception + + +# set up to test using fixtures with function decorated with +# conftest.fail_on_pvlib_version +@pytest.fixture +def some_data(): + return "some data" + + +def alt_func(*args): + return args + + +@pytest.fixture +def deprec_func(): + return _deprecation.deprecated( + "350.8", alternative="alt_func", name="deprec_func", removal="350.9" + )(alt_func) + + +@fail_on_pvlib_version('350.9') +def test_use_fixture_with_decorator(some_data, deprec_func): + # test that the correct data is returned by the some_data fixture + assert some_data == "some data" + with pytest.warns(_deprecation.pvlibDeprecationWarning): + # test for custom deprecation warning provided by pvlib + deprec_func(some_data) + + @pytest.fixture def renamed_kwarg_func(): """Returns a function decorated by renamed_kwarg_warning. diff --git a/pvlib/tests/test_conftest.py b/pvlib/tests/test_conftest.py index e848ed19c1..c0baf7654d 100644 --- a/pvlib/tests/test_conftest.py +++ b/pvlib/tests/test_conftest.py @@ -1,50 +1,6 @@ import pytest -import pandas from pvlib.tests import conftest -from pvlib.tests.conftest import fail_on_pvlib_version - -from pvlib._deprecation import pvlibDeprecationWarning, deprecated - -@pytest.mark.xfail(strict=True, - reason='fail_on_pvlib_version should cause test to fail') -@fail_on_pvlib_version('0.0') -def test_fail_on_pvlib_version(): - pass - - -@fail_on_pvlib_version('100000.0') -def test_fail_on_pvlib_version_pass(): - pass - - -@pytest.mark.xfail(strict=True, reason='ensure that the test is called') -@fail_on_pvlib_version('100000.0') -def test_fail_on_pvlib_version_fail_in_test(): - raise Exception - - -# set up to test using fixtures with function decorated with -# conftest.fail_on_pvlib_version -@pytest.fixture() -def some_data(): - return "some data" - - -def alt_func(*args): - return args - - -deprec_func = deprecated('350.8', alternative='alt_func', - name='deprec_func', removal='350.9')(alt_func) - - -@fail_on_pvlib_version('350.9') -def test_use_fixture_with_decorator(some_data): - # test that the correct data is returned by the some_data fixture - assert some_data == "some data" - with pytest.warns(pvlibDeprecationWarning): # test for deprecation warning - deprec_func(some_data) @pytest.mark.parametrize('function_name', ['assert_index_equal',