Skip to content

Expose templated source tests

Phil Dawson requested to merge phil/expose-templated-tests into master

Description

Make it possible for plugin authors to leverage buildstream's suite of generic source tests.

  1. In order to run a custom source type through this test suite a plugin author must: Adding the following code into a conftest.py in a project's test suite will allow pytest to discover the suite of source tests.

    import pytest
    from buildstream.plugintestutils import sourcetests_collection_hook
    
    
    # This hook enables pytest to collect the templated source tests from
    # buildstream.plugintestutils
    def pytest_sessionstart(session):
        sourcetests_collection_hook(session)

    The tests will then be discovered as part of whichever test package contains this code in a conftest.py.

  2. Subclass buildstream.plugintestutils.Repo, implementing the functionality appropriate to their source plugin

  3. Use the register_repo_kind method provided by buildstream.plugintestutils to register the new Repo type with the test suite. This must be done somewhere which willl be executed prior to pytest performing test collection, probably in a conftest.py or __init__.py file at an appropriate location(s) in the test suite.

Changes proposed in this merge request:

  • Expose Repo class as part of the buildstream.plugintestutils API
  • Move templated source tests from tests.sources.generic into buildstream.plugintestutil._sourcetests.
  • Provide an easy way to register source types to run though the templated test suites

This merge request, when approved, will close issue/bug: #944 (closed)

Note:

This MR is most easily reviewed commit by commit. The majority of the files changed are ammending imports due to the movement of repo.py from tests.testutils to buildstream.plugintestutils

Edited by Phil Dawson

Merge request reports