1+
2+ try :
3+ from pathlib import Path
4+
5+ import logging
6+ import sys
7+ import pytest
8+ import manim
9+
10+
11+ """
12+ import cairo
13+ import moderngl
14+
15+ def pytest_report_header(config):
16+ try:
17+ ctx = moderngl.create_standalone_context()
18+ info = ctx.info
19+ ctx.release()
20+ except Exception as e:
21+ raise Exception("Error while creating moderngl context") from e
22+
23+ return (
24+ f"\n Cairo Version: {cairo.cairo_version()}",
25+ "\n OpenGL information",
26+ "------------------",
27+ f"vendor: {info['GL_VENDOR'].strip()}",
28+ f"renderer: {info['GL_RENDERER'].strip()}",
29+ f"version: {info['GL_VERSION'].strip()}\n ",
30+ )
31+ """
32+
33+ """
34+ def pytest_addoption(parser):
35+ parser.addoption(
36+ "--skip_slow",
37+ action="store_true",
38+ default=False,
39+ help="Will skip all the slow marked tests. Slow tests are arbitrarily marked as such.",
40+ )
41+ parser.addoption(
42+ "--show_diff",
43+ action="store_true",
44+ default=False,
45+ help="Will show a visual comparison if a graphical unit test fails.",
46+ )
47+ parser.addoption(
48+ "--set_test",
49+ action="store_true",
50+ default=False,
51+ help="Will create the control data for EACH running tests. ",
52+ )
53+
54+
55+ def pytest_configure(config):
56+ config.addinivalue_line("markers", "skip_end_to_end: mark test as end_to_end test")
57+
58+
59+ def pytest_collection_modifyitems(config, items):
60+ if not config.getoption("--skip_slow"):
61+ return
62+ else:
63+ slow_skip = pytest.mark.skip(
64+ reason="Slow test skipped due to --disable_slow flag.",
65+ )
66+ for item in items:
67+ if "slow" in item.keywords:
68+ item.add_marker(slow_skip)
69+ """
70+
71+ # @pytest.fixture(autouse=True)
72+ # def temp_media_dir(tmpdir, monkeypatch, request):
73+ # if isinstance(request.node, pytest.DoctestItem):
74+ # monkeypatch.chdir(tmpdir)
75+ # yield tmpdir
76+ # else:
77+ # with manim.tempconfig({"media_dir": str(tmpdir)}):
78+ # assert manim.config.media_dir == str(tmpdir)
79+ # yield tmpdir
80+
81+
82+
83+ @pytest .fixture
84+ def config ():
85+ saved = manim .config .copy ()
86+ # we need to return the actual config so that tests
87+ # using tempconfig pass
88+ manim .config .renderer = "cairo" # does this help against flakiness?
89+ yield manim .config
90+ manim .config .update (saved )
91+
92+
93+ @pytest .fixture
94+ def dry_run (config ):
95+ config .dry_run = True
96+ yield
97+
98+
99+ @pytest .fixture
100+ def reset_cfg_file ():
101+ cfgfilepath = Path (__file__ ).parent / "test_cli" / "manim.cfg"
102+ original = cfgfilepath .read_text ()
103+ yield
104+ cfgfilepath .write_text (original )
105+
106+
107+ @pytest .fixture
108+ def using_opengl_renderer (config ):
109+ """Standard fixture for running with opengl that makes tests use a standard_config.cfg with a temp dir."""
110+ config .renderer = "opengl"
111+ yield
112+ # as a special case needed to manually revert back to cairo
113+ # due to side effects of setting the renderer
114+ config .renderer = "cairo"
115+
116+ except :
117+ import logging
118+ logging .error ("Failed to import pytest fixtures from conftest.py" )
0 commit comments