-
Notifications
You must be signed in to change notification settings - Fork 26
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
Cleaner failure reports #62
base: main
Are you sure you want to change the base?
Conversation
I have tried the suggested way of overwriting index 227be0a..4eb8d24 100644
--- a/test_framework/runner.py
+++ b/test_framework/runner.py
@@ -24,6 +24,16 @@ from test_framework.tacky.common import CHAPTER as TACKY_OPT_CHAPTER
from test_framework.tacky.suite import Optimizations
+class MyTextTestResult(unittest.TextTestResult):
+ def addFailure(self, test, err):
+ if self.showAll:
+ self._write_status(test, "FAIL")
+ elif self.dots:
+ self.stream.write("F")
+ self.stream.flush()
+
+
def get_optimization_flags(
latest_chapter: int,
optimization_opt: Optional[test_framework.tacky.suite.Optimizations],
@@ -522,7 +532,11 @@ def main() -> int:
unittest.installHandler()
# run it
- runner = unittest.TextTestRunner(verbosity=args.verbose, failfast=args.failfast)
+ runner = unittest.TextTestRunner(
+ verbosity=args.verbose,
+ failfast=args.failfast,
+ resultclass=MyTextTestResult,
+ )
result = runner.run(test_suite)
if result.wasSuccessful():
return 0 The problem is this, though:
and I didn't want to open up the whole thing... If you see an easier way of making this happen, let me know. The chosen method of disabling all stacktrace might be a bit of overkill. Maybe it also could work like this: class MyTextTestResult(unittest.TextTestResult):
def addFailure(self, test, err):
old_tblim = sys.tracebacklimit
sys.tracebacklimit = 0
super(MyTextTestResult, self).addFailure(test, err)
sys.tracebacklimit = old_tblim but in my test that crashed loudly with
and left me confused. |
Thanks for opening this PR! I'll take a look at the (Some error messages don't include a filename at all and probably should, but that can wait for another PR.) |
Your POC |
yes, looking at this now.
3.11.4 is the version it failed. I just also installed and tried 3.12.4, which failed similarly. Maybe your code looks subtly different than mine? |
I added relative paths to:
I'm now not anymore entirely sure whether using relative paths (to Also, as written in the first sub-bullet, I haven't really tried all my changes. I'm not far enough with the content to test all the scenarios. Could still work, but please really double check my code 😅 |
Thanks for updating this!
We can do this by 1) setting each test's docstring to be the file's relative path: index f6812e6..dc401fc 100644
--- a/test_framework/basic.py
+++ b/test_framework/basic.py
@@ -596,6 +596,8 @@ def make_invalid_test(program: Path) -> Callable[[TestChapter], None]:
def test_invalid(self: TestChapter) -> None:
self.compile_failure(program)
+ test_invalid.__doc__ = str(program.relative_to(TEST_DIR))
+
return test_invalid
@@ -725,6 +727,7 @@ def make_valid_tests(
else:
# for stages besides "run", just test that compilation succeeds
test_method = make_test_valid(program)
+ test_method.__doc__ = str(program.relative_to(TEST_DIR))
tests.append((test_name, test_method))
return tests and 2) overriding class MyTextTestResult(unittest.TextTestResult):
def addFailure(self, test: Any, err: Any) -> None:
super(MyTextTestResult, self).addFailure(test, (None, err[1], None))
def getDescription(self, test: unittest.TestCase) -> str:
return test.shortDescription() or "MISSING"
|
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.
Took me a while to get back to this.
Thanks for your pointers, very helpful!
I applied your suggestions and tested this new addFailure
approach with all versions between 3.8 and 3.12 (so all of the current ones, I guess)
I think this is getting somewhere :)
- We now have a short title, which still clearly indicated the location of the test
- Are keeping the absolute paths in the test description
- Dropping the stacktrace if it's a test failure
- What I have not added yet is a flag to enable this for test framework developers like you. Do you think that'd be helpful to have?
Note: I have decided to not squash commits yet to hopefully make it easier for you to review, but we can certainly squash it in the end.
@@ -310,22 +311,27 @@ def validate_runs( | |||
expected_retcode = expected["return_code"] | |||
expected_stdout = expected.get("stdout", "") | |||
|
|||
def build_error_message_wrapped(): |
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.
Not sure if that's really necessary, but instead of adding the source_file
three times I decided to create this closure :)
@@ -23,6 +23,16 @@ | |||
from test_framework.tacky.suite import Optimizations | |||
|
|||
|
|||
class MyTextTestResult(unittest.TextTestResult): |
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.
This works fine!
Now the only thing left is naming, I guess. This is a very lazy name... Should we stick to it?
An alternative could be ConciseTextTestResult
or using any other of these adjectives like brief, terse, reduced, succinct...
super(MyTextTestResult, self).addFailure(test, (err[0], err[1], None)) | ||
|
||
def getDescription(self, test: unittest.TestCase) -> str: | ||
return test.shortDescription() or super(MyTextTestResult, self).getDescription( |
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.
I decided to fall back on the description instead of putting "MISSING" :)
Thanks for updating this! I left some nitpicky comments (and we'll need to set docstrings for the Part III tests) but on the whole this is looking good! And not squashing commits yet is useful, thank you. It would be helpful to have a way to re-enable stack traces. We could either add a new flag, or turn them on when the verbosity level is 3 or higher. (Increasing the verbosity past 2 doesn't impact the default test runner behavior, so people could still use |
Adding a note that it might make sense to address #82 as part of this PR |
This PR resolves #61.
compile_failure
)