pytest-dev / pytest-dev/unittest2pytest
Missing necessary parentheses and not allowing equality
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 141
- Forks
- 28
- PR merge metrics
- No merged PRs in 30d
Description
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 abs(mock_sleep.call_args_list[2][0][0]-interval/2 - 1) < 1
This is incorrect for two reasons:
- Parentheses should be added around the 2nd argument to
assertAlmostEqual(or the- 1changed to+ 1). - assertAlmostEqual doesn't error if the difference between the first two arguments equals the delta argument.
(With that said, I just ran unittest2pytest on 28k lines of real test code and this was the only problem I encountered other than the pytest.raises limitation described at the bottom of your README. Nice work!)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing unittest2pytest's rewrite of assertAlmostEqual, using the two transformed examples in the issue as reproduction cases. Check the generated assertion against unittest's delta semantics, including equality, and verify that the output preserves the intended second argument and accepts an exactly equal difference.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100