diff options
| -rw-r--r-- | resources/unittest_template.py | 23 | 
1 files changed, 11 insertions, 12 deletions
| diff --git a/resources/unittest_template.py b/resources/unittest_template.py index 4c9b0bb..7919b5c 100644 --- a/resources/unittest_template.py +++ b/resources/unittest_template.py @@ -18,17 +18,6 @@ class RunnerTestCase(unittest.TestCase):  ### UNIT CODE -# Fake file object not writing anything -DEVNULL = SimpleNamespace(write=lambda *_: None, flush=lambda *_: None) - -RESULT = io.StringIO() -ORIGINAL_STDOUT = sys.stdout - -# stdout/err is patched in order to control what is outputted by the runner -sys.stdout = DEVNULL -sys.stderr = DEVNULL - -  def _exit_sandbox(code: int) -> NoReturn:      """      Exit the sandbox by printing the result to the actual stdout and exit with the provided code. @@ -74,10 +63,20 @@ def _main() -> None:  try: +    # Fake file object not writing anything +    DEVNULL = SimpleNamespace(write=lambda *_: None, flush=lambda *_: None) + +    RESULT = io.StringIO() +    ORIGINAL_STDOUT = sys.stdout + +    # stdout/err is patched in order to control what is outputted by the runner +    sys.stdout = DEVNULL +    sys.stderr = DEVNULL +          # Load the user code as a global module variable      module = _load_user_module()      _main()  except Exception:      print("Uncaught exception:\n", file=RESULT)      traceback.print_exc(file=RESULT) -    _exit_sandbox(99) +    _exit_sandbox(99)
\ No newline at end of file | 
