Message ID | 20230616123651.915234-6-peter.hoyes@arm.com |
---|---|
State | Accepted, archived |
Commit | 79bc14003000ab439262272dae6a99961f7c14c7 |
Headers | show |
Series | RFC: Support pytest for bitbake self-tests | expand |
On Fri, 16 Jun 2023 at 14:38, Peter Hoyes <peter.hoyes@arm.com> wrote: > > From: Peter Hoyes <Peter.Hoyes@arm.com> > > To support running the bitbake self-tests using pytest, add a > pytest.ini This enables these tests to be run using the following > command from the bitbake directory. > > pytest > > For now, testpaths only includes the bitbake selftests. > > Add a note to the README. > bitbake/lib/bb/tests/conftest.py | 8 ++++++++ > diff --git a/bitbake/lib/bb/tests/conftest.py b/bitbake/lib/bb/tests/conftest.py > new file mode 100644 > index 0000000000..59a8c6753b > --- /dev/null > +++ b/bitbake/lib/bb/tests/conftest.py > @@ -0,0 +1,8 @@ > +import pathlib > +import pytest > + > +BB_BIN_PATH = pathlib.Path(__file__).parents[3].resolve() / 'bin' > + > +@pytest.fixture(autouse=True) > +def bitbake_path(monkeypatch): > + monkeypatch.setenv('PATH', str(BB_BIN_PATH), prepend=':') The addition and purpose of this file should be explained. Alex
On 16/06/2023 13:53, Alexander Kanavin wrote: > On Fri, 16 Jun 2023 at 14:38, Peter Hoyes <peter.hoyes@arm.com> wrote: >> From: Peter Hoyes <Peter.Hoyes@arm.com> >> >> To support running the bitbake self-tests using pytest, add a >> pytest.ini This enables these tests to be run using the following >> command from the bitbake directory. >> >> pytest >> >> For now, testpaths only includes the bitbake selftests. >> >> Add a note to the README. >> bitbake/lib/bb/tests/conftest.py | 8 ++++++++ >> diff --git a/bitbake/lib/bb/tests/conftest.py b/bitbake/lib/bb/tests/conftest.py >> new file mode 100644 >> index 0000000000..59a8c6753b >> --- /dev/null >> +++ b/bitbake/lib/bb/tests/conftest.py >> @@ -0,0 +1,8 @@ >> +import pathlib >> +import pytest >> + >> +BB_BIN_PATH = pathlib.Path(__file__).parents[3].resolve() / 'bin' >> + >> +@pytest.fixture(autouse=True) >> +def bitbake_path(monkeypatch): >> + monkeypatch.setenv('PATH', str(BB_BIN_PATH), prepend=':') > The addition and purpose of this file should be explained. > > Alex "conftest.py" is a pytest feature [1] for test module-specific configuration, which is ignored by unittest. The intention here is to automatically configure the PATH to avoid extra manual steps after checkout. I can either add a comment to this effect in v2, or drop this file and require the user to manually configure the PATH, as for bitbake-selftest. Peter [1] https://docs.pytest.org/en/7.3.x/reference/fixtures.html#conftest-py-sharing-fixtures-across-multiple-files
diff --git a/bitbake/README b/bitbake/README index bdb1e81dc1..78610e65f1 100644 --- a/bitbake/README +++ b/bitbake/README @@ -53,3 +53,8 @@ testsuite as follows: export PATH=$(pwd)/bin:$PATH bin/bitbake-selftest + +The testsuite can alternatively be executed using pytest, e.g. obtained from PyPI (in this +case, the PATH is configured automatically): + + pytest diff --git a/bitbake/lib/bb/tests/conftest.py b/bitbake/lib/bb/tests/conftest.py new file mode 100644 index 0000000000..59a8c6753b --- /dev/null +++ b/bitbake/lib/bb/tests/conftest.py @@ -0,0 +1,8 @@ +import pathlib +import pytest + +BB_BIN_PATH = pathlib.Path(__file__).parents[3].resolve() / 'bin' + +@pytest.fixture(autouse=True) +def bitbake_path(monkeypatch): + monkeypatch.setenv('PATH', str(BB_BIN_PATH), prepend=':') diff --git a/bitbake/pytest.ini b/bitbake/pytest.ini new file mode 100644 index 0000000000..3927e49021 --- /dev/null +++ b/bitbake/pytest.ini @@ -0,0 +1,7 @@ +[pytest] +addopts = --import-mode=importlib +minversion = 7.3 +junit_family = xunit1 +python_files = tests/*.py +pythonpath = lib +testpaths = lib/bb