-
Notifications
You must be signed in to change notification settings - Fork 664
Move to nose2 only #6146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Move to nose2 only #6146
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
2d49363
Move to nose2 only
klecki 116bb82
Replace unsupported -m regex by attributes
klecki b34940e
Fix : -> .
klecki 16191d8
Greptile suggestion - use one TC instance
klecki a0e63e7
Remove remaining nose
klecki 8239ace
Lint
klecki cd8e0f7
Path attrib plugin to work with generators
klecki d222d9b
Fix test discovery for nose2
klecki 532ef3f
Fixes
JanuszL 512cc6c
Fix
JanuszL 8084775
Review fix
JanuszL ccaf8c4
Review fix
JanuszL b031f79
Defer callback construction to test run time to avoid OOM at discovery
JanuszL 9a11b20
Fix _make_expected_out crash when passed a pre-built ndarray
JanuszL 9083f27
Review fix
JanuszL 84110e2
Consolidate TF dataset test classes sharing setUp into single class
JanuszL c245614
Fix
JanuszL 8f41ff0
Add missing file
JanuszL 4a861c3
Fix
JanuszL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| # Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """ | ||
| Custom nose2 plugin to filter generator test functions by attributes | ||
| before they are called (preventing imports of optional dependencies or other code execution). | ||
|
|
||
| This plugin monkey-patches the Generators plugin's _testsFromGeneratorFunc | ||
| method to check attributes before calling generator functions. | ||
| """ | ||
|
|
||
| from nose2.events import Plugin | ||
| import logging | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class AttributeGeneratorFilter(Plugin): | ||
| """Filter generator functions by attributes before calling them.""" | ||
|
|
||
| configSection = "attrib-generators" | ||
| alwaysOn = True | ||
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
| self._patched = False | ||
|
|
||
| def _get_attrib_plugin(self): | ||
| """Get the attrib plugin from the session.""" | ||
| for plugin in self.session.plugins: | ||
| if plugin.__class__.__name__ == "AttributeSelector": | ||
| return plugin | ||
| return None | ||
|
|
||
| def _build_attribs_list(self, attrib_plugin): | ||
| """Build the attribs list from the attrib plugin's -A configuration. | ||
|
|
||
| NOTE: This intentionally replicates the -A parsing logic from | ||
| nose2's AttributeSelector.moduleLoadedSuite (nose2/plugins/attrib.py). | ||
| nose2 does not cache a pre-parsed form of attrib_plugin.attribs; the | ||
| raw -A strings are parsed on every moduleLoadedSuite call. Because we | ||
| need the parsed representation here (to call validateAttrib), we must | ||
| duplicate this parsing. If nose2 changes how it parses -A expressions | ||
| (e.g. adding quoting, ranges, or OR-groups), this copy must be updated | ||
| to match. | ||
| """ | ||
| attribs = [] | ||
|
|
||
| # Handle -A (attribute) filters — mirrors AttributeSelector.moduleLoadedSuite | ||
| for attr in attrib_plugin.attribs: | ||
| attr_group = [] | ||
| for attrib in attr.strip().split(","): | ||
| if not attrib: | ||
| continue | ||
| items = attrib.split("=", 1) | ||
| if len(items) > 1: | ||
| # "name=value" | ||
| key, value = items | ||
| else: | ||
| key = items[0] | ||
| if key[0] == "!": | ||
| # "!name" | ||
| key = key[1:] | ||
| value = False | ||
| else: | ||
| # "name" | ||
| value = True | ||
| attr_group.append((key, value)) | ||
| attribs.append(attr_group) | ||
|
|
||
| return attribs | ||
|
|
||
| def _matches_attrib_filter(self, test_func, attrib_plugin): | ||
| """Check if test_func matches the attribute filter from attrib plugin.""" | ||
| if not attrib_plugin: | ||
| return True | ||
|
|
||
| if not attrib_plugin.attribs: | ||
| return True | ||
|
|
||
| # Build attribs list using attrib plugin's logic | ||
| attribs = self._build_attribs_list(attrib_plugin) | ||
|
|
||
| if not attribs: | ||
| return True | ||
|
|
||
| # Use the plugin's validateAttrib method | ||
| return attrib_plugin.validateAttrib(test_func, attribs) | ||
|
|
||
| def _patch_generator_plugin(self): | ||
| """Monkey-patch the Generators plugin to check attributes first.""" | ||
| if self._patched: | ||
| return | ||
|
|
||
| # Find the Generators plugin | ||
| gen_plugin = None | ||
| for plugin in self.session.plugins: | ||
| if plugin.__class__.__name__ == "Generators": | ||
| gen_plugin = plugin | ||
| break | ||
|
|
||
| if not gen_plugin: | ||
| log.warning("Could not find Generators plugin to patch") | ||
| return | ||
|
|
||
| # Save original method | ||
| original_tests_from_gen = gen_plugin._testsFromGeneratorFunc | ||
| attrib_filter_self = self | ||
|
|
||
| # Create patched method | ||
| def patched_tests_from_gen(event, obj): | ||
| """Check attributes before calling generator function.""" | ||
| attrib_plugin = attrib_filter_self._get_attrib_plugin() | ||
|
|
||
| # Check if generator function matches attribute filter | ||
| if not attrib_filter_self._matches_attrib_filter(obj, attrib_plugin): | ||
| log.debug(f"Skipping generator {obj.__name__} due to attribute filter") | ||
| return [] # Return empty list | ||
|
|
||
| # Call original method | ||
| return original_tests_from_gen(event, obj) | ||
|
|
||
| # Monkey-patch it | ||
| gen_plugin._testsFromGeneratorFunc = patched_tests_from_gen | ||
| self._patched = True | ||
| log.debug("Patched Generators plugin to check attributes") | ||
|
|
||
| def handleArgs(self, event): | ||
| """Patch right after argument handling, before test discovery.""" | ||
| self._patch_generator_plugin() | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.