Using pytest with Lager

Simple pytest example

pytest-simple.py
import sys
import pytest

def meaning():
   return 42

def test_equality():
   assert meaning() == meaning()

def test_false():
   assert False is False

def test_meaning():
   assert meaning() == 43


if __name__ == '__main__':
   args = sys.argv
   if args[-1].startswith('::'):
      args = args[1:]
      args[-1] = __file__ + args[-1]
   sys.exit(pytest.main(args))

Save the above listing as pytest-simple.py

➜  lager python pytest-simple.py
============================= test session starts ==============================
platform linux -- Python 3.8.5, pytest-6.0.2, py-1.9.0, pluggy-0.13.1
rootdir: /tmp
collected 3 items

tmp59ouy9ec.py ..F                                                       [100%]

=================================== FAILURES ===================================
_________________________________ test_meaning _________________________________

    def test_meaning():
>      assert meaning() == 43
E      assert 42 == 43
E       +  where 42 = meaning()

tmp59ouy9ec.py:14: AssertionError
=========================== short test summary info ============================
FAILED tmp59ouy9ec.py::test_meaning - assert 42 == 43
========================= 1 failed, 2 passed in 0.10s ==========================

-- can be used to demarcate arguments that should be passed through to pytest itself (as opposed to being lager python arguments). To run one specific test function, :: can be used as a prefix to the function name:

➜  lager python pytest-simple.py -- ::test_equality
============================= test session starts ==============================
platform linux -- Python 3.8.6, pytest-6.0.2, py-1.10.0, pluggy-0.13.1
rootdir: /tmp
collected 1 item

tmpmtiviawa.py .                                                         [100%]

============================== 1 passed in 0.06s ===============================