Skip to content

refactor(tests): replace exec() with importlib in example runner#1628

Open
OfficialSerge wants to merge 1 commit intoNVIDIA:mainfrom
OfficialSerge:feat/refactor-example-tests
Open

refactor(tests): replace exec() with importlib in example runner#1628
OfficialSerge wants to merge 1 commit intoNVIDIA:mainfrom
OfficialSerge:feat/refactor-example-tests

Conversation

@OfficialSerge
Copy link

Description

This PR is in response to the following TODO item in cuda_core/tests/example_tests/utils.py.

# TODO: Refactor the examples to give them a common callable `main()` to avoid needing to use exec here?
exec(script, env if env else {})

Key Changes

  • refactor run_example in utils.py using importlib, adding support for both main() and exec() scripts, tracebacks should now provide real line number feedback, thus paving the way for us to progressively enhance the remaining non-module tests and examples.
  • updated test_basic_example.py to use pathlib.Path instead of os.path.join().
  • removed redundant manual Device(0) and set_current() calls in test class, instead relying on exiting deinit_cuda() fixture for consistent teardowns (see conftest.py)

Next Steps

  • go through the remaining examples still without main() and refactor them into Python modules, some examples are currently refactored while others are still plain executables so it's a mix.

@copy-pr-bot
Copy link
Contributor

copy-pr-bot bot commented Feb 14, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

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.

1 participant