Lessons Learned

contact@vinta.com.br

ipdb can also be used when debugging issues with environments other than your local one. ipdb.runcall helps one debug issues on method calls through and IPython shell, and it's as simple as:

>>> import ipdb
>>> import xpto_method  # the method one wants to debug
>>> ipdb.runcall(xpto_method, 'method arg')
(ipdb) ...

ipdb.runcall receives the method one wants to call as the first argument, and subsequent to that the target method arguments.

For more usage examples, check: https://iqbalnaved.wordpress.com/2013/10/17/how-to-debug-in-ipython-using-ipdb/

Did you like?
1

pytest makes it easier to flag tests that are expected to fail. It's really useful when in development, e.g., feature not yet implement or bug not totally fixed. Making use of it is as simple as:

import pytest

@pytest.mark.xfail
def test_xpto():
    ...

This way, it'll be presented differently in the terminal report and one can track whether a test is failing as expected or unexpectedly passing.

While the test marked as expected to fail will be presented as xfailed in the test summary, if it passes it'll be displayed as xpassed and when that happens it's not displayed as passed because that test was marked to expect failure.

One can even go further and set a reason to why a test is expected to fail, one can set a reason:

import pytest

@pytest.mark.xfail(reason="feature not totally implemented")
def test_xpto():
    ...

To display this reason in the test summary, one can use the -r option with the corresponding short letters shown in progress(x for xfail and/or X for xpass), e.g. pytest -rxX.

For more information, check the documentation at: https://docs.pytest.org/en/latest/skipping.html#xfail-mark-test-functions-as-expected-to-fail

Did you like?
1