Skip to content

Commit fecd10c

Browse files
authored
ci: initial implementation of top-level pytest tests (#433)
``` $ poetry init $ poetry add --dev pytest $ poetry add --dev pytest-subtests ```
1 parent 821a004 commit fecd10c

File tree

7 files changed

+217
-0
lines changed

7 files changed

+217
-0
lines changed

.github/workflows/code-quality.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,46 @@ jobs:
2828
exit 1
2929
fi
3030
31+
pytest-tests:
32+
runs-on: ubuntu-latest
33+
env:
34+
poetry_version: '1.8.3'
35+
steps:
36+
- uses: actions/checkout@v4
37+
38+
- name: Cache poetry in ~/.local
39+
uses: actions/cache/restore@v4
40+
id: cache-poetry-restore
41+
with:
42+
path: ~/.local
43+
key: "${{ runner.os }}-local-${{ env.poetry_version }}"
44+
45+
- name: Install poetry
46+
if: steps.cache-poetry-restore.outputs.cache-hit != 'true'
47+
run: pip install poetry==${{ env.poetry_version }}
48+
49+
- name: Save cache
50+
if: steps.cache-poetry-restore.outputs.cache-hit != 'true'
51+
uses: actions/cache/save@v4
52+
with:
53+
path: ~/.local
54+
key: ${{ steps.cache-poetry-restore.outputs.cache-primary-key }}
55+
56+
- name: Set up Python
57+
id: setup-python
58+
uses: actions/setup-python@v5
59+
with:
60+
python-version: '3.12'
61+
cache: 'poetry'
62+
63+
- name: Configure poetry
64+
run: poetry env use "${{ steps.setup-python.outputs.python-path }}"
65+
66+
- name: Install deps
67+
run: poetry install --sync
68+
69+
- run: poetry run pytest
70+
3171
code-static-analysis:
3272
runs-on: ubuntu-latest
3373
steps:

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ podman run -it -p 8888:8888 quay.io/opendatahub/workbench-images:jupyter-mini
5151

5252
### Deploy & Test
5353

54+
#### Running Python selftests in Pytest
55+
56+
```shell
57+
pip install poetry
58+
poetry env use /usr/bin/python3.12
59+
poetry config virtualenvs.in-project true
60+
poetry install --sync
61+
62+
poetry run pytest
63+
```
64+
5465
#### Notebooks
5566

5667
Deploy the notebook images in your Kubernetes environment using:

poetry.lock

Lines changed: 108 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[tool.poetry]
2+
name = "notebooks"
3+
version = "2024.1"
4+
authors = []
5+
description = "Open Data Hub / OpenShift AI Notebook / Workbench images, and tests for the same in Python."
6+
readme = "README.md"
7+
package-mode = false
8+
9+
[tool.poetry.dependencies]
10+
python = "~3.12"
11+
12+
13+
[tool.poetry.group.dev.dependencies]
14+
pytest = "^8.2.2"
15+
pytest-subtests = "^0.12.1"
16+
17+
[build-system]
18+
requires = ["poetry-core"]
19+
build-backend = "poetry.core.masonry.api"

pytest.ini

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# https://docs.pytest.org/en/7.1.x/reference/reference.html#configuration-options
2+
3+
[pytest]
4+
addopts = --strict-markers --capture=no --tb=short
5+
6+
required_plugins = pytest-subtests
7+
8+
junit_logging = all
9+
junit_log_passing_tests = False
10+
11+
log_cli = True
12+
log_cli_date_format = %Y-%m-%d %H:%M:%S
13+
log_cli_format = %(asctime)s %(levelname)s %(message)s
14+
log_cli_level = INFO
15+
16+
log_file = logs/pytest-logs.txt
17+
log_file_level = DEBUG

tests/__init__.py

Whitespace-only changes.

tests/test_main.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from __future__ import annotations
2+
3+
import pathlib
4+
import tomllib
5+
from typing import TYPE_CHECKING
6+
7+
if TYPE_CHECKING:
8+
import pytest_subtests
9+
10+
PROJECT_ROOT = pathlib.Path(__file__).parent.parent
11+
12+
13+
def test_image_pipfiles(subtests: pytest_subtests.plugin.SubTests):
14+
for file in PROJECT_ROOT.glob("**/Pipfile"):
15+
with subtests.test(msg="checking Pipfile", pipfile=file):
16+
directory = file.parent # "ubi9-python-3.9"
17+
ubi, lang, python = directory.name.split("-")
18+
19+
with open(file, "rb") as fp:
20+
pipfile = tomllib.load(fp)
21+
assert "requires" in pipfile, "Pipfile is missing a [[requires]] section"
22+
assert pipfile["requires"]["python_version"] == python, "Pipfile does not declare the expected Python version"

0 commit comments

Comments
 (0)