|
5 | 5 | import pytest |
6 | 6 |
|
7 | 7 | from pvlib import _deprecation |
| 8 | +from .conftest import fail_on_pvlib_version |
8 | 9 |
|
9 | 10 | import warnings |
10 | 11 |
|
11 | 12 |
|
| 13 | +@pytest.mark.xfail(strict=True, |
| 14 | + reason='fail_on_pvlib_version should cause test to fail') |
| 15 | +@fail_on_pvlib_version('0.0') |
| 16 | +def test_fail_on_pvlib_version(): |
| 17 | + pass # pragma: no cover |
| 18 | + |
| 19 | + |
| 20 | +@fail_on_pvlib_version('100000.0') |
| 21 | +def test_fail_on_pvlib_version_pass(): |
| 22 | + pass |
| 23 | + |
| 24 | + |
| 25 | +@pytest.mark.xfail(strict=True, reason='ensure that the test is called') |
| 26 | +@fail_on_pvlib_version('100000.0') |
| 27 | +def test_fail_on_pvlib_version_fail_in_test(): |
| 28 | + raise Exception |
| 29 | + |
| 30 | + |
| 31 | +# set up to test using fixtures with function decorated with |
| 32 | +# conftest.fail_on_pvlib_version |
| 33 | +@pytest.fixture |
| 34 | +def some_data(): |
| 35 | + return "some data" |
| 36 | + |
| 37 | + |
| 38 | +def alt_func(*args): |
| 39 | + return args |
| 40 | + |
| 41 | + |
| 42 | +@pytest.fixture |
| 43 | +def deprec_func(): |
| 44 | + return _deprecation.deprecated( |
| 45 | + "350.8", alternative="alt_func", name="deprec_func", removal="350.9" |
| 46 | + )(alt_func) |
| 47 | + |
| 48 | + |
| 49 | +@fail_on_pvlib_version('350.9') |
| 50 | +def test_use_fixture_with_decorator(some_data, deprec_func): |
| 51 | + # test that the correct data is returned by the some_data fixture |
| 52 | + assert some_data == "some data" |
| 53 | + with pytest.warns(_deprecation.pvlibDeprecationWarning): |
| 54 | + # test for custom deprecation warning provided by pvlib |
| 55 | + deprec_func(some_data) |
| 56 | + |
| 57 | + |
12 | 58 | @pytest.fixture |
13 | 59 | def renamed_kwarg_func(): |
14 | 60 | """Returns a function decorated by renamed_kwarg_warning. |
|
0 commit comments