TestingΒΆ
The pyroapi package includes tests to ensure new backends conform to the standard API, indeed these tests serve as the formal API description.
To add tests to your new backend say in project/test/
follow these steps (or see the example in funsor):
- Create a new directory
project/test/pyroapi/
. - Create a file
project/test/pyroapi/conftest.py
and a hook to treat missing features as xfail:
import pytest
def pytest_runtest_call(item):
try:
item.runtest()
except NotImplementedError as e:
pytest.xfail(str(e))
- Create a file
project/test/pyroapi/test_pyroapi.py
and define abackend
fixture:
import pytest
from pyroapi import pyro_backend
from pyroapi.tests import * # noqa F401
@pytest.yield_fixture
def backend():
with pyro_backend("my_backend"):
yield
- Test your backend with pytest
pytest -vx test/pyroapi