Skip to content
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

Raising error in unittest's setUpClass causes autograder breaking exception #40

Open
alexadkins opened this issue Apr 11, 2024 · 2 comments
Labels

Comments

@alexadkins
Copy link

Describe the bug
Raising an Assertion Error in unittest's setUpClass method causes exception in jsontestrunner's getLeaderboardData

To Reproduce

import unittest
from gradescope_utils.autograder_utils.decorators import (
    weight,
    number,
    leaderboard,
)

class TestAutograder(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        raise AssertionError("compile for all tests failed")
        return super().setUpClass()
    
    @number(1.1)
    @weight(1)
    def test_01(self):
        "Test 01"
        pass

Expected behavior
Raised error would have populated results.json for all test cases of that class.

Instead, received following error:

The autograder produced the following output:

Traceback (most recent call last):
  File "/usr/lib/python3.10/unittest/suite.py", line 166, in _handleClassSetUp
    setUpClass()
  File "/autograder/source/tests/test.py", line 14, in setUpClass
    raise AssertionError("compile for all tests failed")
AssertionError: compile for all tests failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/autograder/source/run_tests.py", line 8, in <module>
    JSONTestRunner(visibility='visible',stdout_visibility='visible').run(suite)
  File "/usr/local/lib/python3.10/dist-packages/gradescope_utils/autograder_utils/json_test_runner.py", line 196, in run
    test(result)
  File "/usr/lib/python3.10/unittest/suite.py", line 84, in __call__
    return self.run(*args, **kwds)
  File "/usr/lib/python3.10/unittest/suite.py", line 122, in run
    test(result)
  File "/usr/lib/python3.10/unittest/suite.py", line 84, in __call__
    return self.run(*args, **kwds)
  File "/usr/lib/python3.10/unittest/suite.py", line 122, in run
    test(result)
  File "/usr/lib/python3.10/unittest/suite.py", line 84, in __call__
    return self.run(*args, **kwds)
  File "/usr/lib/python3.10/unittest/suite.py", line 114, in run
    self._handleClassSetUp(test, result)
  File "/usr/lib/python3.10/unittest/suite.py", line 176, in _handleClassSetUp
    self._createClassOrModuleLevelException(result, e,
  File "/usr/lib/python3.10/unittest/suite.py", line 236, in _createClassOrModuleLevelException
    self._addClassOrModuleLevelException(result, exc, errorName, info)
  File "/usr/lib/python3.10/unittest/suite.py", line 246, in _addClassOrModuleLevelException
    result.addError(error, sys.exc_info())
  File "/usr/local/lib/python3.10/dist-packages/gradescope_utils/autograder_utils/json_test_runner.py", line 136, in addError
    self.processResult(test, err)
  File "/usr/local/lib/python3.10/dist-packages/gradescope_utils/autograder_utils/json_test_runner.py", line 123, in processResult
    if self.getLeaderboardData(test)[0]:
  File "/usr/local/lib/python3.10/dist-packages/gradescope_utils/autograder_utils/json_test_runner.py", line 51, in getLeaderboardData
    column_name = getattr(getattr(test, test._testMethodName), '__leaderboard_column__', None)
AttributeError: '_ErrorHolder' object has no attribute '_testMethodName'
@alexadkins alexadkins added the bug label Apr 11, 2024
@gregbell26
Copy link

I fixed this issue in my fork (see #38).

GS doesn't seem to be responsive here for some goofy reason, but if you want to use my fork with your autograder you can add
git+https://github.com/gregbell26/gradescope-utils to your requirements.txt instead of the official package.

Im also working on a complete rewrite of this package that will support the new features that the GS team has added to the platform.

@gregbell26
Copy link

I now have an official package that fixes this.
https://pypi.org/project/HybridJSONTestRunner/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants