Skip to content

Metashade render test integration#12

Merged
ppenenko merged 13 commits into
metashade/devfrom
metashade/render_tests
Jun 24, 2026
Merged

Metashade render test integration#12
ppenenko merged 13 commits into
metashade/devfrom
metashade/render_tests

Conversation

@ppenenko

@ppenenko ppenenko commented Jun 24, 2026

Copy link
Copy Markdown
Member

This pull request refactors the Metashade render tests integration in the contrib folder. It resolves Pytest namespace clashes during VS Code test discovery, isolates test outputs, keeps the codebase DRY, and prevents the tests from dirtying the Metashade submodule when run.

Key Enhancements

  1. Resolved Pytest Namespace Clashes:

    • Removed all from conftest import ... imports from the test files. This prevents Python/Pytest from loading contrib/metashade/tests/conftest.py as the global conftest module cache key under sys.modules, which previously broke test discovery in VS Code.
    • Standard test collection helper functions (get_repo_root, get_stdlib_files, get_adsk_files, should_skip_element, get_element_skip_reason) are now defined locally in test_render.py without requiring external imports.
  2. Clean Submodule Environment (No Submodule Dirtying):

    • Updated the contrib/metashade submodule to commit 779bc46fa68be45068447ecd315ac88664f420aa, which introduces the METASHADE_MTLX_PYTEST_REF_DIR environment variable.
    • Configured a workspace-level .env file to set METASHADE_MTLX_PYTEST_REF_DIR=contrib/tests/metashade_ref.
    • Updated .vscode/settings.json to explicitly point to this .env file via "python.envFile".
    • Any reference/baseline updates triggered by Metashade's tests are now automatically redirected to contrib/tests/metashade_ref/ inside the parent repository rather than modifying the contrib/metashade submodule, keeping it completely clean.
    • Committed the generated reference files (source_code_nodes.txt, test purple/add implementations) to the parent repository under contrib/tests/metashade_ref/.
  3. DRY Shared Render Logic:

    • Refactored contrib/tests/test_render.py and contrib/tests/test_render_metashade.py to share a common rendering and baseline image comparison helper function run_render_test_file(...).
    • The geometry streams modification helper (add_additional_test_streams) is defined in test_render.py as a regular function and imported cleanly in conftest.py (locally inside the fixture) and test_render_metashade.py without any complex fixture factories or circular imports.
  4. Isolated Render Outputs:

    • Directed Metashade overridden outputs to a distinct gitignored folder (contrib/renders/metashade_schlick/) to avoid stomping on standard render test outputs.
  5. VS Code Test Explorer Crash Fix on Windows:

    • Removed the "-n", "auto" argument from python.testing.pytestArgs in .vscode/settings.json on Windows. Concurrently launching 20+ worker processes for ultra-fast tests previously caused named pipe buffer overflows, crashing test runs in Test Explorer.

Verification

All 227 standard and 162 Metashade unit tests execute and pass cleanly:

# Standard and ADSK tests
python -m pytest contrib/tests

# Metashade tests
python -m pytest contrib/metashade/tests
============ 227 passed, 65 skipped, 909 subtests passed in 42.85s ============
============ 162 passed in 7.66s ==============================================

@ppenenko ppenenko changed the title Metashade/render tests Refactor Metashade render tests integration and resolve namespace clashes Jun 24, 2026
@ppenenko ppenenko changed the title Refactor Metashade render tests integration and resolve namespace clashes Metashade render test integration Jun 24, 2026
@ppenenko

Copy link
Copy Markdown
Member Author

Relying on metashade/metashade#197

@ppenenko ppenenko marked this pull request as ready for review June 24, 2026 19:35
@ppenenko ppenenko requested a review from Copilot June 24, 2026 19:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the contrib render test setup to avoid pytest namespace clashes during VS Code discovery, share render/baseline logic between standard and Metashade-driven tests, and redirect Metashade reference artifacts into the parent repo.

Changes:

  • Moved render test collection helpers and element skip logic into contrib/tests/test_render.py and introduced shared run_render_test_file(...).
  • Added a new Metashade override render test (test_render_metashade.py) plus checked-in Metashade reference/override artifacts under contrib/tests/metashade_ref/.
  • Updated workspace configuration (.env, VS Code settings/launch) to wire Metashade reference redirection and include contrib/tests in test discovery.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
contrib/tests/test_render.py Inlines helper functions previously imported from conftest and adds run_render_test_file(...) + stream helpers.
contrib/tests/test_render_metashade.py New targeted Metashade override render tests for Schlick materials.
contrib/tests/metashade_ref/test_metashade_add_color3_genglsl_impl.mtlx Adds Metashade-generated node implementation descriptor.
contrib/tests/metashade_ref/test_metashade_add_color3_genglsl_impl.glsl Adds Metashade-generated GLSL implementation.
contrib/tests/metashade_ref/test_metashade_add_color3_defs.mtlx Adds Metashade-generated node definition.
contrib/tests/metashade_ref/test_dummy_purple_genglsl_impl.mtlx Adds Metashade-generated dummy implementation descriptor.
contrib/tests/metashade_ref/test_dummy_purple_genglsl_impl.glsl Adds Metashade-generated dummy GLSL implementation.
contrib/tests/metashade_ref/test_dummy_purple_defs.mtlx Adds Metashade-generated dummy node definition.
contrib/tests/metashade_ref/source_code_nodes.txt Adds a reference list of source-code nodes used by Metashade tests.
contrib/tests/metashade_ref/mx_generalized_schlick_bsdf_metashade_genglsl_impl.mtlx Adds Metashade wrapper implementation descriptor for Schlick BSDF override.
contrib/tests/metashade_ref/mx_generalized_schlick_bsdf_metashade_genglsl_impl.glsl Adds Metashade wrapper GLSL that includes/calls the stdlib Schlick implementation.
contrib/tests/conftest.py Removes duplicated stream helper logic and imports add_additional_test_streams from test_render.
.vscode/settings.json Points VS Code Python to .env and includes contrib/tests in pytest args.
.vscode/launch.json Updates Graph Editor debug launch to use the new Metashade reference folder.
.env Sets METASHADE_MTLX_PYTEST_REF_DIR for VS Code-driven runs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread contrib/tests/test_render_metashade.py Outdated
Comment on lines +73 to +83
@pytest.fixture(scope="session")
def output_dir(self, request, repo_root) -> Path:
"""Override output_dir to place Metashade results under their own root."""
opt = request.config.getoption("--output-dir")
if opt:
path = Path(opt) / "metashade_schlick"
else:
path = repo_root / "contrib" / "renders" / "metashade_schlick"
path.mkdir(parents=True, exist_ok=True)
return path

Comment on lines +143 to +152
"""Test all renderable elements in a stdlib material file using the Schlick override."""
run_render_test_file(
mtlx_file=mtlx_file,
subtests=subtests,
renderer=schlick_renderer,
data_library=schlick_stdlib,
search_path=schlick_search_path,
output_dir=output_dir,
assert_image_matches_baseline=assert_image_matches_baseline
)
Comment on lines +107 to +113
"""
Add additional test streams required by MaterialX test suite.

This mirrors the C++ addAdditionalTestStreams() in RenderUtil.cpp,
adding geometry attributes needed by geompropvalue, streams, and
struct_texcoord tests.
"""
…d update add_additional_test_streams docstring

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.

Comment thread contrib/tests/test_render.py Outdated
Comment on lines +31 to +37
files = []
for rel_path_str in targeted:
mtlx_file = materials_root / rel_path_str
if mtlx_file.exists():
files.append(pytest.param(mtlx_file, id=rel_path_str))

return files
Comment thread contrib/tests/test_render_metashade.py Outdated
Comment on lines +78 to +82
# 2. Add Metashade override path
metashade_mtlx_path = repo_root / "contrib" / "tests" / "metashade_ref"
if metashade_mtlx_path.exists():
custom_sp.append(metashade_mtlx_path.as_posix())

Comment on lines +90 to +94
# 1. Load Metashade Schlick override first
override_mtlx = repo_root / "contrib" / "tests" / "metashade_ref" / "mx_generalized_schlick_bsdf_metashade_genglsl_impl.mtlx"
if override_mtlx.exists():
mx.readFromXmlFile(lib, override_mtlx.as_posix())

- Remove unused `List` import from test_render.py (comment #4)
- get_schlick_test_files(): skip explicitly if no targeted files found (comment #5)
- schlick_search_path fixture: skip if metashade_ref dir is missing (comment #6)
- schlick_stdlib fixture: skip if Schlick override .mtlx file is missing (comment #7)
@ppenenko ppenenko requested a review from Copilot June 24, 2026 21:28
These files (metashade_ref/ dir and override .mtlx) are committed to the
repo, not optional env dependencies. Their absence means the environment
is broken, which should surface as a failure, not a silent skip.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Comment on lines +176 to 177
_add_stream_if_missing(mesh, f"i_{GEOMPROP}_geompropvalue_color4", GEOMPROP, 1, 4, fill_color4)
def find_renderable_elements(doc):
Comment on lines +128 to +130
# Second UV set - copy from texcoord0
_add_stream_if_missing(mesh, f"i_{TEXCOORD}_1", TEXCOORD, 1, 2,
lambda d: [d.__setitem__(i, uv[i]) for i in range(len(uv))])
@ppenenko ppenenko merged commit 84d85a0 into metashade/dev Jun 24, 2026
34 of 36 checks passed
@ppenenko ppenenko deleted the metashade/render_tests branch June 24, 2026 21:56
@ppenenko

Copy link
Copy Markdown
Member Author

Follow-up issue for the next step: #13 — restructuring overrides into per-environment subdirectories with --library compatibility for MaterialXView/GraphEditor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants