diff --git a/yt_idv/rendering_contexts/__init__.py b/yt_idv/rendering_contexts/__init__.py index 50dbcff..76e0765 100644 --- a/yt_idv/rendering_contexts/__init__.py +++ b/yt_idv/rendering_contexts/__init__.py @@ -1,7 +1,5 @@ import os -import OpenGL.error - def render_context(engine="pyglet", **kwargs): """ @@ -18,6 +16,13 @@ def render_context(engine="pyglet", **kwargs): RenderingContext """ + + # PYOPENGL_PLATFORM must be set before any opengl imports + if engine in ("osmesa", "egl"): + os.environ["PYOPENGL_PLATFORM"] = engine + + import OpenGL.error + if engine == "pyglet": from .pyglet_context import PygletRenderingContext @@ -35,12 +40,10 @@ def render_context(engine="pyglet", **kwargs): raise Exception(extramsg) from oee raise oee elif engine == "osmesa": - os.environ["PYOPENGL_PLATFORM"] = "osmesa" from .osmesa_context import OSMesaRenderingContext return OSMesaRenderingContext(**kwargs) elif engine == "egl": - os.environ["PYOPENGL_PLATFORM"] = "egl" from .egl_context import EGLRenderingContext return EGLRenderingContext(**kwargs) diff --git a/yt_idv/tests/conftest.py b/yt_idv/tests/conftest.py new file mode 100644 index 0000000..8c9a39d --- /dev/null +++ b/yt_idv/tests/conftest.py @@ -0,0 +1,7 @@ +import os + + +def pytest_configure(config): + # this will get run before all tests, before collection and + # any opengl imports that happen within test files. + os.environ["PYOPENGL_PLATFORM"] = "osmesa" diff --git a/yt_idv/tests/test_yt_idv.py b/yt_idv/tests/test_yt_idv.py index 11fa8c3..67a0e33 100644 --- a/yt_idv/tests/test_yt_idv.py +++ b/yt_idv/tests/test_yt_idv.py @@ -14,11 +14,6 @@ from yt_idv.scene_data.curve import CurveCollection, CurveData -@pytest.fixture(autouse=True) -def pyopengl_setup(monkeypatch): - monkeypatch.setenv("PYOPENGL_PLATFORM", "osmesa") - - @pytest.fixture() def osmesa_fake_amr(): """Return an OSMesa context that has a "fake" AMR dataset added, with "radius"