Skip to content

SyntaxError not catched when named explicte but unittest does #255

@buhtz

Description

@buhtz

My current environment: Green 3.4.0, Coverage 6.2, Python 3.9.4 on Windows10

I run a test by naming it explicit:

C:\Users\buhtzch\tab-cloud\_transfer\greenbug>py -3 -m green tests.test_my

Ran 0 tests in 0.316s using 8 processes

No Tests Found

There are two problems about that output:

  1. The test ist not found. (Run 0 tests)
  2. A SyntaxError is not thrown.

Unittest itself shows this output

C:\Users\buhtzch\tab-cloud\_transfer\greenbug>py -3 -m unittest tests.test_my
Traceback (most recent call last):
  File "C:\IUK\Python\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\IUK\Python\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\IUK\Python\lib\unittest\__main__.py", line 18, in <module>
    main(module=None)
  File "C:\IUK\Python\lib\unittest\main.py", line 100, in __init__
    self.parseArgs(argv)
  File "C:\IUK\Python\lib\unittest\main.py", line 147, in parseArgs
    self.createTests()
  File "C:\IUK\Python\lib\unittest\main.py", line 158, in createTests
    self.test = self.testLoader.loadTestsFromNames(self.testNames,
  File "C:\IUK\Python\lib\unittest\loader.py", line 220, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "C:\IUK\Python\lib\unittest\loader.py", line 220, in <listcomp>
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "C:\IUK\Python\lib\unittest\loader.py", line 154, in loadTestsFromName
    module = __import__(module_name)
  File "C:\Users\buhtzch\tab-cloud\_transfer\greenbug\tests\test_my.py", line 9
    X X
      ^
SyntaxError: invalid syntax

This is the MWE. The file is in a folder named tests and there is also an empty __init__.py in the same folder.

import unittest

class TestMY(unittest.TestCase):
    """
    """
    def test_valid_scores(self):
        """All items with valid values."""
        #self.assertTrue(True)
        X X

The last line should cause a syntax error.

When you fix the syntax of the MWE the test is found by green. So I think the not catched SyntaxError also causing the missing test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions