Friday, June 24, 2016

PyDev 5.1.2: pytest integration

PyDev 5.1.2 is now out. The major change is in the pytest integration.

For those that don't know about it, pytest (http://pytest.org) is a Python test framework which requires less scaffolding to make tests (you don't need a hierarchy such as in PyUnit, just test methods in a module and asserts for checks suffice, it takes care of providing a reasonable error message -- also, it has an interesting fixture concept which allows structuring the test environment in a way more natural then through an inheritance hierarchy with unittest.TestCase.setUp/tearDown).

If you want to use pytest, in PyDev, the runner in the preferences > PyDev > PyUnit has to be set as pytest.

It's interesting to note that PyDev makes it trivial to just run a single test: you can select the test by using the method navigation (Ctrl+Shift+Up and Ctrl+Shift+Down) and press Ctrl+F9: this will open the outline for selecting which tests to run with only that test selected by default, then you can press Enter to run the test (or Shift+Enter to debug it) -- note that this works with the regular unittest too, not only with pytest.