Open Bug 1397437 Opened 3 years ago Updated 2 years ago

[Tracking] Convert all python unittests to the pytest format

Categories

(Testing :: Python Test, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

People

(Reporter: ahal, Unassigned)

References

(Depends on 2 open bugs)

Details

As of bug 1339178 we are now running our python unittests with the 'pytest' framework. This was possible because pytest has the ability to run unittest-based tests out of the box, so most of the tests didn't need to be upgraded.

But the pytest format is much simpler, cleaner and easier to read/write. Plus it has a ton of nifty features that are lacking from the unittest framework. To take full advantage of this, we should convert as many of our existing unittest-based tests to pytest as possible.

In general, I think the migration would look something like this:
1) Convert all self.assertFoo functions to simple 'assert' statements. So:
self.assertEquals(foo, 1)

becomes:
assert foo == 1

2) Move all test functions to top level module functions. So:
class TestFoo(TestCase):
    def test_foo(self):
        ...

becomes:
def test_foo():
    ...

3) Move all shared logic to pytest fixtures [1]. So:
class TestFoo(TestCase):
    def helper(self):
        ...

becomes:
@pytest.fixture
def helper():
    ...

def test_foo(helper):
    ...

I think that should more or less cover most migrations. There will definitely be a few edge cases and some light refactoring required along the way, but it shouldn't be too bad. This is a tracking bug, so please file new bugs to convert specific test directories and make them block this bug.

[1] https://docs.pytest.org/en/latest/fixture.html
Component: General → Python Test
Depends on: 1445273
You need to log in before you can comment on or make changes to this bug.