Converting asserts with unitest2pytest
Once you have changed the test runner to pytest, you can take advantage of writing plain assert statements instead of self.assert*
methods.
Converting all the method calls is boring and error-prone, that's why the unittest2pytest
tool exists. It converts all self.assert*
method calls to plain asserts, and also converts self.assertRaises
calls to the appropriate pytest idiom.
Install it using pip
:
λ pip install unittest2pytest
Once installed, you can now execute it on the files you want:
λ unittest2pytest test_simple2.py RefactoringTool: Refactored test_simple2.py --- test_simple2.py (original) +++ test_simple2.py (refactored) @@ -5,6 +5,7 @@ import unittest from collections import namedtuple from pathlib import Path +import pytest DATA = """ Main Grid,48,44 @@ -49,12 +50,12 @@ self.grids = list(iter_grids_from_csv(self.filepath)) def test_read_properties(self): - self.assertEqual(self.grids[0], GridData("Main Grid", 48, 44)) ...