Repository navigation
bpo-30523: regrtest: Add --list-cases option #2238
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
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import datetime | ||
| import doctest | ||
| import faulthandler | ||
| import locale | ||
| import os | ||
|
|
@@ -10,9 +11,10 @@ | |
| import tempfile | ||
| import textwrap | ||
| import time | ||
| import unittest | ||
| from test.libregrtest.cmdline import _parse_args | ||
| from test.libregrtest.runtest import ( | ||
| findtests, runtest, | ||
| findtests, runtest, get_abs_module, | ||
| STDTESTS, NOTTESTS, PASSED, FAILED, ENV_CHANGED, SKIPPED, RESOURCE_DENIED, | ||
| INTERRUPTED, CHILD_ERROR, | ||
| PROGRESS_MIN_TIME, format_test_result) | ||
|
|
@@ -248,6 +250,31 @@ def list_tests(self): | |
| for name in self.selected: | ||
| print(name) | ||
|
|
||
| def _list_cases(self, suite): | ||
| for test in suite: | ||
| if isinstance(test, unittest.loader._FailedTest): | ||
| continue | ||
| elif isinstance(test, doctest.DocTestCase): | ||
| continue | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this if: doctest falls into the the unittest.TestCase case, and... it just works! I'm able to pass to output to -m test --matchfile=tests and only these doctest tests are executed! |
||
| if isinstance(test, unittest.TestSuite): | ||
| self._list_cases(test) | ||
| elif isinstance(test, unittest.TestCase): | ||
| print(test.id()) | ||
|
|
||
| def list_cases(self): | ||
| for test in self.selected: | ||
| abstest = get_abs_module(self.ns, test) | ||
| try: | ||
| suite = unittest.defaultTestLoader.loadTestsFromName(abstest) | ||
| self._list_cases(suite) | ||
| except unittest.SkipTest: | ||
| self.skipped.append(test) | ||
|
|
||
| if self.skipped: | ||
| print(file=sys.stderr) | ||
| print(count(len(self.skipped), "test"), "skipped:", file=sys.stderr) | ||
| printlist(self.skipped, file=sys.stderr) | ||
|
|
||
| def rerun_failed_tests(self): | ||
| self.ns.verbose = True | ||
| self.ns.failfast = False | ||
|
|
@@ -499,6 +526,10 @@ def _main(self, tests, kwargs): | |
| self.list_tests() | ||
| sys.exit(0) | ||
|
|
||
| if self.ns.list_cases: | ||
| self.list_cases() | ||
| sys.exit(0) | ||
|
|
||
| self.run_tests() | ||
| self.display_result() | ||
|
|
||
|
|
@@ -525,7 +556,7 @@ def count(n, word): | |
| return "%d %ss" % (n, word) | ||
|
|
||
|
|
||
| def printlist(x, width=70, indent=4): | ||
| def printlist(x, width=70, indent=4, file=None): | ||
| """Print the elements of iterable x to stdout. | ||
|
|
||
| Optional arg width (default 70) is the maximum line length. | ||
|
|
@@ -536,7 +567,8 @@ def printlist(x, width=70, indent=4): | |
| blanks = ' ' * indent | ||
| # Print the sorted list: 'x' may be a '--random' list or a set() | ||
| print(textwrap.fill(' '.join(str(elt) for elt in sorted(x)), width, | ||
| initial_indent=blanks, subsequent_indent=blanks)) | ||
| initial_indent=blanks, subsequent_indent=blanks), | ||
| file=file) | ||
|
|
||
|
|
||
| def main(tests=None, **kwargs): | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this import (see above).