Coverage for plotting/conftest.py: 100%

1"""

2 Plotting - Pytest Configuration

3===============================

4

5 Configure *pytest* to use the *Matplotlib* *AGG* headless backend. This

6 enables the plotting unit tests to run without creating windows in IDEs such

7 as *VSCode*.

8"""

9

10 import matplotlib as mpl

11 import pytest

12

13 from colour.hints import Generator

14

15 __author__ = "Colour Developers"

16 __copyright__ = "Copyright 2013 Colour Developers"

17 __license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"

18 __maintainer__ = "Colour Developers"

19 __email__ = "colour-developers@colour-science.org"

20 __status__ = "Production"

21

22 __all__ = [

23 "mpl_headless_backend",

24]

25

26

27@pytest.fixture(autouse=True, scope="session")

28 def mpl_headless_backend() -> Generator[None, None, None]:

29 """

30 Configure *Matplotlib* for headless testing.

31

32 This pytest fixture is automatically applied to any tests in this

33 package or any subpackages at the beginning of the pytest session.

34

35 Yields

36 ------

37 Generator

38 *Matplotlib* unit tests.

39 """

40

41 current_backend = mpl.get_backend()

42 mpl.use("AGG")

43 yield

44 mpl.use(current_backend)