Open Bug 1397437 Opened 4 years ago Updated 4 years ago
[Tracking] Convert all python unittests to the pytest format
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 . 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.  https://docs.pytest.org/en/latest/fixture.html
You need to log in before you can comment on or make changes to this bug.