-
Notifications
You must be signed in to change notification settings - Fork 2
/
conftest.py
73 lines (47 loc) · 2.29 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
Copyright (c) 2021-2023 MeteoSwiss, contributors listed in AUTHORS.
Distributed under the terms of the 3-Clause BSD License.
SPDX-License-Identifier: BSD-3-Clause
Module contains: pytest utilities
"""
# Import from python packages and modules
import pytest
def pytest_addoption(parser) -> None:
""" A nifty little function that allows to feed command line arguments to the pytest command,
e.g.:
pytest --MPL_STYLE=latex
Intended to enable the adjustment of the plotting style when running test locally.
Reference:
https://docs.pytest.org/en/6.2.x/example/simple.html#pass-different-values-to-a-test-function-depending-on-command-line-options
"""
parser.addoption("--MPL_STYLE", action="store", default='base',
help="The required dynamic.MPL_STYLE value, e.g. latex or metsymb." +
" Defaults to base.")
parser.addoption("--DO_SCIPLOTS", action="store_true", default=False,
help="If used, will generate the plots when running the scientific stability" +
"tests.")
@pytest.fixture(scope='session')
def mpls(request):
""" A pytext fixture to identify whether the MPL_STYLE argument was fed to pytest, or not.
Adapted from the similar function in dvas, which itself was adapted from the response of ipetrik
on `StackOverflow <https://stackoverflow.com/questions/40880259>`__
To use this, simply call it as an argument in any of the test function, e.g.:
def test_some_func(a, b, mpls):
...
if mpls:
dynamic.AMPYCLOUD_PRMS['MPL_STYLE'] = mpls
"""
return request.config.getoption("--MPL_STYLE")
@pytest.fixture(scope='session')
def do_sciplots(request):
""" A pytext fixture to decide whether to create plots (or not) when testing the
scientific stability of ampycloud.
Adapted from the similar function in dvas, which itself was adapted from the response of ipetrik
on `StackOverflow <https://stackoverflow.com/questions/40880259>`__
To use this, simply call it as an argument in any of the test function, e.g.:
def test_some_func(a, b, do_sciplots):
...
if do_sciplots:
diagnostic(...)
"""
return request.config.getoption("--DO_SCIPLOTS")