[pytest-dev] Automatically converting unittest asserts to py.test asserts.

Cesar Canassa cesar.canassa at gmail.com
Mon Jan 19 17:41:20 CET 2015


Abdelilah:

You have to create a wrapper script and call it from there, here is a
sample one:

from lib2to3.refactor import RefactoringTool
> import sys
>
> if __name__ == '__main__':
>     if len(sys.argv) < 2:
>         sys.exit('Usage: topytest.py [FILE ...]')
>     refactoring_tool = RefactoringTool(['fix_pytest'])
>     refactoring_tool.refactor(sys.argv[1:], write=True)


Holger:

Sure! I will start a repository for it.


Best,
Cesar Canassa

On Mon, Jan 19, 2015 at 1:50 PM, holger krekel <holger at merlinux.eu> wrote:

> Hi Cesar,
>
> On Mon, Jan 19, 2015 at 13:33 -0200, Cesar Canassa wrote:
> > Hi,
> >
> > In my current company, I recently switched from using Unittest to Py.test
> > in our Flask application. I loved Py.test and I decided to start
> rewriting
> > our tests using Py.test style asserts instead of Unittest asserts
> > (self.assertEqual, self.assertFalse, et al).
> >
> > Since we have already written hundreds of thousands of lines of test
> code,
> > manually converting the tests would take too long, so I have decided to
> > automate the process. The automation effort resulted in this script:
> >
> > https://gist.github.com/canassa/4fd63d682d90f5e3f07e
> >
> > The script is not perfect, you still need to manually review some changes
> > it makes, but at least in our project it worked amazingly well, so I
> > decided to share it with you.
>
> Thanks.  There also is a tool that (for historic reason) comes with "py",
> namely py.convert_unittest, which is always installed with py.test.
> Can you imagine to do a proper pytest_convert_unittest repository which
> we can then link prominently from pytest.org?  I am sure there are others
> who are interested in this.
>
> cheers,
> holger
>
> >
> > Best,
> > Cesar Canassa
>
> > _______________________________________________
> > pytest-dev mailing list
> > pytest-dev at python.org
> > https://mail.python.org/mailman/listinfo/pytest-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20150119/7db656cf/attachment.html>


More information about the pytest-dev mailing list