Using unittest2 with Pydev test runner

2011-05-24
2013-03-15
  • Robert Rollins

    Robert Rollins - 2011-05-24

    I've recently started using unittest2 to test my Python 2.6 project, because I want the new testing features from Python 2.7's unittest (unittest2 is a backport).  However, it appears that Pydev's test runner ignores my "if __name__ == '__main__': unittest2.main()" block, and runs the regular unittest.main() function instead.  This ends up breaking a bunch of the unittest2 functionality, and I'd really like to know how to get around that.

    I can make the code work by running the module as a regular "Python run" instead of "Python unit-test", but I can't do that for more than one module at a time (as far as I know). Since my code shop's standard pre-deploy testing procedure is to right-click the project in the package explorer and choose "Run As > Python unit-test", I need my code to work properly when batch executed like that.

     
  • Fabio Zadrozny

    Fabio Zadrozny - 2011-05-24

    The only proper way is PyDev supporting what you want.

    What features are breaking? Can you check the latest nightly to see if it works for you? (I remember making some fixes related to that, just not sure what's your actual use case).

    Cheers,

    Fabio

     
  • Robert Rollins

    Robert Rollins - 2011-05-24

    Is there an easy way to install the nightly builds into Eclipse without messing up my existing PyDev 2.0.0 install?  I'm on OSX 10.6 using Eclipse Helios SR2.

    I apologize for not mentioning my use case, that was remiss of me.  Though there are probably other problems I haven't run into yet, I'm mostly worried about the TestResult class.  unittest.TestResult does not support several of the new features added in unittest2.TestResult, like test skipping and expected failures (it's missing the addSkip and addExpectedFailure methods). 

    My test class inherits from unittest2.TestCase, but whatever PyDev's test runner is doing makes it use the old unittest.TestResult class.  unittest2 fails gracefully, noticing that there's no addSkip method and treating the test as an automatic pass.  However, there's 2 major problems with this:
    1. It throws a DeprecationWarning because it's being given a unittest.TestResult object instead of the expected unittest2.TestResult.
    2. Skipped tests show as passes, which makes it impossible to tell which tests were skipped, and the "here's why this test is being skipped" message isn't shown.

    This might be fairly simply to solve, since unittest2 provides a command-line script for running tests, called unit2.  Maybe it could be added as an option on PyDev's Pyunit preference page?

     
  • Fabio Zadrozny

    Fabio Zadrozny - 2011-05-25

    The only way to test without disturbing your current environment would be installing it in a separate version of eclipse and pointing to a new workspace.

    Anyways, just took a quick look and it seems PyDev won't handle your use-case… Please create a feature request for that expliciting your use case.

    Cheers,

    Fabio

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks