unittest2pytest
unittest2pytest copied to clipboard
helps rewriting Python `unittest` test-cases into `pytest` test-cases
In my work on https://github.com/certbot/certbot/pull/9585, `unittest2pytest` rewrote these lines: ``` self.assertAlmostEqual(mock_sleep.call_args_list[1][0][0], interval - 1, delta=1) self.assertAlmostEqual(mock_sleep.call_args_list[2][0][0], interval/2 - 1, delta=1) ``` as ``` assert abs(mock_sleep.call_args_list[1][0][0]-interval - 1) < 1 assert...
Closes #63. Change `AlmostOp()` to rewrite `self.assertAlmostEqual(3, 3.0)` to `3 == approx(3.0)` instead of `round(abs(3 - 3.0), 7) == 0`. Still needs tests. Also currently requires adding `from pytest import...
The replacement for `self.assertAlmostEqual(3, 3.0)` is `round(abs(3 - 3.0), 7) == 0`. How about replacing it with `pytest.approx(3) == 3.0` instead? [[pytest docs](https://docs.pytest.org/en/7.1.x/reference/reference.html#pytest-approx)]
input ```python with self.assertRaises(Exception) as ctx: sut() self.assertIn("msg", str(ctx.exception)) ``` expected output ```python with pytest.raises(Exception) as ctx: sut() assert "msg" in str(ctx.value) ```
When writing unittest.py tests, often the test methods are camel-cased, e.g. `def testThing(self): ...`. With pytest, the usual convention is snake_case (as per pep8), i.e. `def test_thing():`. It'd be nice...
One of my test files (https://github.com/nedbat/coveragepy/blob/coverage-5.4/tests/test_testing.py) was converted into invalid code. I don't know what it is about that file that caused it, though it is a bit twisty: it's...
I'm trying to package your module as an rpm package. So I'm using the typical build, install and test cycle used on building packages from non-root account. - "setup.py build"...
and also update supported Python versions in tox.ini. #54
As https://www.python.org/dev/peps/pep-0584/#dict-d1-d2 points out, > [`dict(d1, **d2)`] only works when d2 is entirely string-keyed > >```python >>>> d1 = {"spam": 1} >>>> d2 = {3665: 2} >>>> dict(d1, **d2) >Traceback...