Question

I have a relatively large test code base which I will migrate from nose to py.test. I would also like to take advantage of py.tests 'bare assert' functionality so that I'd need to make a lot of the following changes (for example):

self.assertEquals(a, b)

->

assert a == b

The code base is in practice too large for me to consider doing this by hand. With some git and sed magic I can get rid of about half of the self.asserts, but that still leaves me with an awful lot to do and the script is already getting somewhat complex.

It occurred to me that I'm probably not the first person to have done this. So: have any nice scripts to do this kind of thing? Or know of any nice tool that can programmatically refactor python (note: I'm aware of python-rope but to be honest at a glance that didn't seem particularly convenient)

Was it helpful?

Solution

You could use py.convert_unittest from the pycmd package for transforming the self.assert* alternatively. It doesn't deal with rewriting the inheritance, though.

Not sure it makes sense but you might also checkout the related pycmd hg repository and tweak the script, possibly submitting pull requests. If you like, i'd help factoring out the script into a new repo (also on github, if you prefer) and then advertise it so people with the same problem can start sharing efforts. As i am not using unittest myself for a longer time (surprise!) i don't have interest to drive this effort but i am willing to help along.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top