Repository: CleanCut/green

Issue:
SyntaxError not catched when named explicte but unittest does
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.

Discussion:
coveralls: 
[![Coverage Status](https://coveralls.io/builds/45811062/badge)](https://coveralls.io/builds/45811062)

Coverage remained the same at 100.0% when pulling **fc5b08c056e73952e59ab0bc80cd7bc7fdde7847 on detect-dotname-syntax-error** into **e75ce6a8f82b06fa07eed1bfb989ef511e4cd195 on main**.


Patch:
diff --git a/.github/workflows/label-sponsors.yml b/.github/workflows/label-sponsors.yml
deleted file mode 100644
index 02472bd..0000000
--- a/.github/workflows/label-sponsors.yml
+++ /dev/null
@@ -1,16 +0,0 @@
-name: Label sponsors
-on:
-  pull_request:
-    types: [opened]
-  issues:
-    types: [opened]
-jobs:
-  build:
-    name: is-sponsor-label
-    runs-on: ubuntu-latest
-    steps:
-      - uses: JasonEtco/is-sponsor-label-action@v1
-        with:
-          label: Sponsor Request ❤️
-        env:
-          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/green/loader.py b/green/loader.py
index ec7a132..203f9bb 100644
--- a/green/loader.py
+++ b/green/loader.py
@@ -246,7 +246,7 @@ class GreenTestLoader(unittest.TestLoader):
                         del tests._tests[index]
 
             except Exception as e:
-                debug("IGNORED exception: {}".format(e))
+                raise Exception("Exception while loading {}: {}".format(target, e))
             if tests and tests.countTestCases():
                 debug("Load method: DOTTED OBJECT - {}".format(target))
                 return flattenTestSuite(tests)


Test patch:
diff --git a/green/test/test_loader.py b/green/test/test_loader.py
index bcab890..52fbd98 100644
--- a/green/test/test_loader.py
+++ b/green/test/test_loader.py
@@ -887,10 +887,9 @@ class TestLoadTargets(unittest.TestCase):
         )
         self.assertEqual(tests.countTestCases(), 1)
 
-    def test_explicit_filename_error(self):
+    def test_syntax_error_by_filename(self):
         """
-        Loading a module by name with a syntax error produces a failure, not a
-        silent absence of its tests.
+        Loading a module by file name with a syntax error produces a crash.
         """
         sub_tmpdir = tempfile.mkdtemp(dir=self.tmpdir)
         fh = open(os.path.join(sub_tmpdir, "mod_with_import_error.py"), "w")
@@ -898,8 +897,46 @@ class TestLoadTargets(unittest.TestCase):
         fh.close()
 
         os.chdir(sub_tmpdir)
-        tests = self.loader.loadTargets("mod_with_import_error.py")
-        self.assertEqual(tests.countTestCases(), 1)
+        hit_exception = False
+        try:
+            self.loader.loadTargets("mod_with_import_error.py")
+        except Exception as e:
+            self.assertIn("invalid syntax", str(e))
+            self.assertIn("mod_with_import_error.py", str(e))
+            hit_exception = True
+        if not hit_exception:
+            self.fail("An exception should have been raised. :-(")
+
+    def test_syntax_error_by_dotname(self):
+        """
+        Loading a module by dotname with a syntax error produces a crash.
+        """
+        sub_tmpdir = tempfile.mkdtemp(dir=self.tmpdir)
+        fh = open(os.path.join(sub_tmpdir, "mod_with_syntax_error.py"), "w")
+        fh.write(
+            dedent(
+                """
+            import unittest
+            class TestSyntax(unittest.TestCase):
+                def test_syntax(self):
+                    syntax error
+            """
+            )
+        )
+        fh.close()
+
+        os.chdir(sub_tmpdir)
+        hit_exception = False
+        try:
+            self.loader.loadTargets("mod_with_syntax_error.TestSyntax.test_syntax")
+        except Exception as e:
+            self.assertIn("invalid syntax", str(e))
+            self.assertIn("mod_with_syntax_error.TestSyntax.test_syntax", str(e))
+            hit_exception = True
+        if not hit_exception:
+            self.fail(
+                "An exception should have been raised about the syntax error. :-("
+            )
 
     def test_file_pattern(self):
         """