ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> visualpython-discuss
visualpython-discuss
Re: [Visualpython-discuss] Unittests don't run with debug
by Robert Ferrell other posts by this author
Nov 7 2003 1:06AM messages near this date
view in the new Beta List Site
Re: [Visualpython-discuss] Unittests don't run with debug | [Visualpython-discuss] Debugging Python extensions with Visual Studio
Thanks for the quick response.  The division of labor is exactly the
workaround I discovered, too.  It actually is a good idea for my work for
other reasons.  But, I thought I ought to learn what was really going on,
since it will probably come up again some other place.

Thanks again.

-robert

<quote who="Eric Promislow"> 
>  It's due to an interaction between the way the Python debugger
>  works, and the way unittest.py works.
> 
>  Visual Python and Komodo both provide graphical front-ends over
>  bdb.py, as do all the other Python debuggers I'm aware of.
>  When you run one of these, __main__ is actually set to bdb,
>  not the program you're trying to debug.  bdb.py does some
>  magic with the symbol table and call stack to stay out of
>  the way, but it doesn't change the value of __main__.
> 
>  Then, unittest filters the attributes of the module to debug,
>  looking for any subclasses of unittest.TestCase.  You
>  provided one, but bdb provides zero.  The solution I would
>  have liked was to be able to say
> 
>      unittest.main(module=<me, not that module called __main__>)
> 
>  but there is no construct.
> 
>  So I did a workaround, and broke your code into two pieces:
> 
>  # innertest.py
> 
>  import unittest
> 
>  class Test_1(unittest.TestCase):
>          """Will print 'Test Ran' if successful."""
>          def test_it(self):
>                  """If you see this message, the test ran."""
>                  print 'Test Ran'
> 
>  # testTest.py
> 
>  import unittest
>  import innerTest
> 
>  if (__name__ == '__main__'):
>          print 'Should see "Ran 1 test", but with debug will see "Ran 0
>  tests".' unittest.main(module=innerTest)
> 
> 
>  Not perfect, but this should help you get going.
> 
>  - Eric
> 
>  On Thu, Nov 06, 2003 at 03:49:24PM -0700, Robert Ferrell wrote:
> > I'm using PyUnit (unittest) for testing.  When I run with debugging
> > the tests do not run.  If I choose "Start Without Debugging" the tests
> > run fine.  What gives?
> >
> > thanks,
> > -robert
> >
> > Here's a script that shows the problem.  Put this into a Visual Studio
> > project and choose "Debug|Start".  Then "Debug|Start Without
> > Debugging". In the first case, test does not run (an error), in the
> > second case test does run.
> >
> > ====testTest.py====
> > """
> > Toy example showing problem when using unittest in Visual Python. When
> > run with the debugger, test does not run.  When run without debugging,
> > test is run properly.  To see the problem, in Visual Studio/Visual
> > Python, 1. Choose Debug|Start, and notice "Ran 0 tests"
> > 2. Choose Debug|Start Without Debugging, and notice "Ran 1 test" """
> >
> > import unittest
> >
> > class Test_1(unittest.TestCase):
> > 	"""Will print 'Test Ran' if successful."""
> > 	def test_it(self):
> > 		"""If you see this message, the test ran."""
> > 		print 'Test Ran'
> >
> > if (__name__ == '__main__'):
> > 	print 'Should see "Ran 1 test", but with debug will see "Ran 0
> > tests".' unittest.main()
> >
> >
> >
> > _______________________________________________
> > Visualpython-discuss mailing list
> > Visualpython-discuss@[...].com
> > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Robert Ferrell
Eric Promislow
Robert Ferrell
Robert Ferrell

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved