Use / run python 2to3 as or as unittest

I used the 2to3 utility to convert code from the command line. What I would like to do is run it basically as unittest. Even if it checks the file, not the parts (functions, methods ...), as it would be normal for unittest.

It does not have to be unittest, and I don’t want to automatically convert files that I just want to track the correspondence of py3 files to unittest like manor. I can't seem to find any documentation or examples for this.

An example and / or documentation would be great.

+4
source share
2 answers

Just use the -3 option with python2.6 + to get Python 3 compliance information.

+2
source

If you are trying to verify that the code will work in Python 3.x, I would suggest a script that copies the source files to a new directory, runs 2to3 on them, and then copies the unit tests on and runs them.

This may seem a little inelegant, but consistent with the spirit of unit testing. You make a number of statements that, in your opinion, should be true regarding the external behavior of the code, regardless of its implementation. If the converted code passes your unit tests, you can consider your code to support Python 3.

+1
source

Source: https://habr.com/ru/post/1309283/


All Articles