CleanCut / green

Green is a clean, colorful, fast python test runner.
MIT License
793 stars 75 forks source link

SyntaxError not catched when named explicte but unittest does #255

Open buhtz opened 2 years ago

buhtz commented 2 years ago

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.

CleanCut commented 2 years ago

The fix for this was included in version 3.4.1. See #256 for details on the fix. Thanks for your detailed report! 😄

buhtz commented 2 years ago

Sorry I would reopen this.

I have nearly the same problem with a ModuleNotFoundError.

When I explicite name the test via green tests.test_reader no tests found and no error is thrown.

When I do discover via green the (expected) ModuleNotFoundError is thrown.

buhtz commented 2 years ago

The ModuleNotFoundError is still there and not catched

CleanCut commented 8 months ago

@buhtz Do you have any information on how to reproduce this?

/cc @sodul for followup if desired