Convert unittest asserts to pytest rewritten asserts.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

dbx-unittest2pytest Build Status

Warning: this is not the official unittest2pytest!

Dropbox developed this package in parallel with (what became) the official pytest-dev package unittest2pytest, that has the same name and does the same thing. It's the one that has the name unittest2pytest on PyPI, and it can convert a few more assertions. Check it out on Github or on PyPI. We've since renamed the project dbx-unittest2pytest to avoid confusion


Convert unittest asserts to pytest rewritten asserts.

py.test supports advanced assertion introspection, allowing it to provide more detailed error messages.

Check out this blog post detailing how it works.

tl;dr If you are using py.test, then "assert a == b" is better than "self.assertEqual(a, b)"

What's the advantage?

Pytest output before:

test/ in test
    self.assertEquals(login.call_count, 1)
E   AssertionError: 0 != 1
    assert login.call_count == 1

Pytest output after:

test/ in test
E   AssertionError: assert 0 == 1
E    +  where 0 = <MagicMock name='mock.desktop_login.login' id='140671857679512'>.call_count

What happens to my test code?


self.assertEqual(a, b)
self.assertEqual(a, None)


assert a == b
assert a is None
assert not a

See unit tests for many more examples.


dbx-unittest2pytest --help
dbx-unittest2pytest --fix=asserts <filename/dirnames>

Run 4x parallel.

dbx-unittest2pytest --fix=asserts -j4 [filename/dirnames]

Write back to original files.

dbx-unittest2pytest --fix=asserts -w [filename/dirnames]


Contributions are welcome. Tests can be run with tox. Lint with flake8 You'll have to agree to Dropbox's CLA.

#Issues If you encounter any problems, please file an issue along with a detailed description.