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

SyntaxError not catched when named explicte but unittest does #255

Open
buhtz opened this issue Jan 19, 2022 · 4 comments · Fixed by #256
Open

SyntaxError not catched when named explicte but unittest does #255

buhtz opened this issue Jan 19, 2022 · 4 comments · Fixed by #256

Comments

@buhtz
Copy link

buhtz commented Jan 19, 2022

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
Copy link
Owner

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

@buhtz
Copy link
Author

buhtz commented Apr 22, 2022

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.

@CleanCut CleanCut reopened this Apr 22, 2022
@buhtz
Copy link
Author

buhtz commented Jun 13, 2022

The ModuleNotFoundError is still there and not catched

@CleanCut
Copy link
Owner

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

  • Operating System name & version
  • Output of green --version
  • Code to reproduce the failure

/cc @sodul for followup if desired

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

Successfully merging a pull request may close this issue.

2 participants