Support use of pytest's --pdb mode.

Review Request #1570 - Created Jan. 6, 2015 and submitted

Information
John Sirois
pants
jsirois/py.test/stdin_unbuffer
908
5b2b607...
Reviewers
pants-reviews
benjyw, lahosken, zundel
The python subprocess spawned to run pytest in
pants.backend.python.test_builder.PythonTestBuilder buffers its stdin
by default ruining the interactive pdb session launched when in `--pdb`
mode.  This fix solves the issue for CPython 2.7 but does not address
CPython 3.x where the same trick will not work.

 src/python/pants/backend/python/test_builder.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Manual testing only on this.

Applied the following diff:

$ git diff tests/python/pants_test/tasks/test_reflect.py
diff --git a/tests/python/pants_test/tasks/test_reflect.py b/tests/python/pants_test/tasks/test_reflect.py
index ddc82dd..21e2db9 100644
--- a/tests/python/pants_test/tasks/test_reflect.py
+++ b/tests/python/pants_test/tasks/test_reflect.py
@@ -27,6 +27,7 @@ class BuildsymsSanityTests(BaseTest):
     # These symbols snuck into old dictionaries, make sure they don't again:
     for unexpected in ['__builtins__', 'Target']:
       self.assertTrue(unexpected not in self._syms.keys(), 'Found %s' % unexpected)
+    self.assertFalse(True)

   def test_java_library(self):
     # Good bet that 'java_library' exists and contains these text blobs

Then ran a successful --pdb session:

$ PANTS_DEV=1 ./pants test tests/python/pants_test/tasks:reflect -- --pdb
...
15:06:56 00:00   [test]
15:06:56 00:00     [run_prep_command]
15:06:56 00:00     [pytest]
15:06:56 00:00       [run]
                     ============== test session starts ===============
                     platform linux2 -- Python 2.7.8 -- py-1.4.26 -- pytest-2.6.4
                     plugins: cov, timeout
                     collected 3 items 

                     tests/python/pants_test/tasks/test_reflect.py F
                     >>>>>>>>>>>>>>>>>>> traceback >>>>>>>>>>>>>>>>>>>>

                     self = <pants_test.tasks.test_reflect.BuildsymsSanityTests testMethod=test_exclude_unuseful>

                         def test_exclude_unuseful(self):
                           # These symbols snuck into old dictionaries, make sure they don't again:
                           for unexpected in ['__builtins__', 'Target']:
                             self.assertTrue(unexpected not in self._syms.keys(), 'Found %s' % unexpected)
                     >     self.assertFalse(True)
                     E     AssertionError: True is not false

                     tests/python/pants_test/tasks/test_reflect.py:30: AssertionError
                     >>>>>>>>>>>>>>>>>> entering PDB >>>>>>>>>>>>>>>>>>
                     > /tmp/tmpUsaHjE/.deps/unittest2-0.8.0-py2.py3-none-any.whl/unittest2/case.py(672)assertFalse()
                     -> raise self.failureException(msg)
                     (Pdb) h

                     Documented commands (type help <topic>):
                     ========================================
                     EOF    bt         cont      enable  jump  pp       run      unt   
                     a      c          continue  exit    l     q        s        until 
                     alias  cl         d         h       list  quit     step     up    
                     args   clear      debug     help    n     r        tbreak   w     
                     b      commands   disable   ignore  next  restart  u        whatis
                     break  condition  down      j       p     return   unalias  where 

                     Miscellaneous help topics:
                     ==========================
                     exec  pdb

                     Undocumented commands:
                     ======================
                     retval  rv

                     (Pdb) quit
...

                     ======= 1 failed, 2 passed in 7.32 seconds =======

FAILURE


               FAILURE
$

CI went green here: https://travis-ci.org/pantsbuild/pants/builds/46134174

John Sirois
John Sirois
John Sirois
John Sirois
Benjy Weinberger
John Sirois
Andy Reitz
John Sirois
Review request changed

Status: Closed (submitted)

Loading...