Coverage for plotting/conftest.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-16 22:49 +1300

1""" 

2Plotting - Pytest Configuration 

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

4 

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

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

7as *VSCode*. 

8""" 

9 

10import matplotlib as mpl 

11import pytest 

12 

13from 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") 

28def 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)