Skip to content

Commit 880b70e

Browse files
committed
updated to ensure all tests pass on linux, this was due to OpenGL and WebGPU contexts clashing and needing to order tests into sub test suites, see conftest for more details
1 parent 049eb31 commit 880b70e

3 files changed

Lines changed: 41 additions & 5 deletions

File tree

src/ncca/ngl/vec3.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,9 @@ def __matmul__(self, rhs):
8484
Returns:
8585
Vec3: A new vector that is the result of multiplying this vector by the matrix.
8686
"""
87-
return Vec3(
88-
self._data[0] * rhs.m[0, 0] + self._data[1] * rhs.m[1, 0] + self._data[2] * rhs.m[2, 0],
89-
self._data[0] * rhs.m[0, 1] + self._data[1] * rhs.m[1, 1] + self._data[2] * rhs.m[2, 1],
90-
self._data[0] * rhs.m[0, 2] + self._data[1] * rhs.m[1, 2] + self._data[2] * rhs.m[2, 2],
91-
)
87+
result = Vec3()
88+
result._data = rhs.m.T @ self._data # More efficient
89+
return result
9290

9391
def set(self, *args: float) -> None:
9492
"""

tests/conftest.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,38 @@
1+
import gc
2+
13
import glfw
24
import OpenGL.GL as gl
35
import pytest
46
import wgpu
57
import wgpu.utils
68

79

10+
def pytest_collection_modifyitems(config, items):
11+
"""
12+
Ensure WebGPU tests run before OpenGL tests to avoid context conflicts
13+
This is fine on mac as both are Metal backends.
14+
"""
15+
16+
opengl_tests = []
17+
webgpu_tests = []
18+
other_tests = []
19+
20+
for item in items:
21+
fixtures = getattr(item, "fixturenames", [])
22+
if "opengl_context" in fixtures or any("opengl" in f for f in fixtures):
23+
opengl_tests.append(item)
24+
elif "webgpu_device" in fixtures or any("webgpu" in f for f in fixtures):
25+
webgpu_tests.append(item)
26+
else:
27+
other_tests.append(item)
28+
29+
# Reorder: Other -> WebGPU -> OpenGL this avoids context conflicts on Linux
30+
# WebGPU cleans nicely OpenGL not so much!
31+
items[:] = other_tests + webgpu_tests + opengl_tests
32+
33+
print(f"\nTest execution order: {len(opengl_tests)} OpenGL, {len(other_tests)} Other, {len(webgpu_tests)} WebGPU")
34+
35+
836
@pytest.fixture(scope="session")
937
def opengl_context():
1038
if not glfw.init():
@@ -34,3 +62,5 @@ def webgpu_device():
3462
if device is None:
3563
raise RuntimeError("Could not get a WebGPU device.")
3664
yield device
65+
del device
66+
gc.collect()

uv.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)