pytest-patches / handle-usageerror

# HG changeset patch
# Parent 4d4ce0192c296472a9cd0ad513d81950e4cc9502
diff --git a/_pytest/main.py b/_pytest/main.py
--- a/_pytest/main.py
+++ b/_pytest/main.py
@@ -64,6 +64,7 @@ def wrap_session(config, doit):
     session = Session(config)
     session.exitstatus = EXIT_OK
     initstate = 0
+    reraise = None
     try:
         config.pluginmanager.do_configure(config)
         initstate = 1
@@ -71,7 +72,7 @@ def wrap_session(config, doit):
         initstate = 2
         doit(config, session)
     except pytest.UsageError:
-        raise
+        reraise = sys.exc_info()
     except KeyboardInterrupt:
         excinfo = py.code.ExceptionInfo()
         config.hook.pytest_keyboard_interrupt(excinfo=excinfo)
@@ -89,6 +90,8 @@ def wrap_session(config, doit):
         session.exitstatus = EXIT_TESTSFAILED
     if initstate >= 1:
         config.pluginmanager.do_unconfigure(config)
+    if reraise:
+        py.builtin._reraise(*reraise)
     return session.exitstatus
 
 def pytest_cmdline_main(config):
diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py
--- a/testing/acceptance_test.py
+++ b/testing/acceptance_test.py
@@ -278,6 +278,15 @@ class TestGeneralUsage:
         ])
         assert 'sessionstarttime' not in result.stderr.str()
 
+    def test_issue134_report_syntaxerror_when_collecting_member(self,testdir):
+        testdir.makepyfile(test_fun="""
+            def test_a():
+                pass
+            def""")
+        result = testdir.runpytest('test_fun.py::test_a')
+        result.stdout.fnmatch_lines(['*SyntaxError*'])
+
+
 class TestInvocationVariants:
     def test_earlyinit(self, testdir):
         p = testdir.makepyfile("""
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.