Skip to content

Commit

Permalink
Add tests workflow for github
Browse files Browse the repository at this point in the history
  • Loading branch information
ishefi committed Mar 13, 2024
1 parent e31fdcf commit 3d12130
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 1 deletion.
39 changes: 39 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Tests

on: push

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/ checkout@v4

- name: Setup Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"


- name: Install Poetry
uses: snok/install-poetry@v4
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- name: Load cached venv
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: |
poetry install --no-root
- name: Run tests
run: ./scripts/runtests.py

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ venv*
.idea*
tmp.png
.DS_Store
.coverage
84 changes: 83 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ types-beautifulsoup4 = "^4.12.0.20240229"
types-pillow = "^10.2.0.20240311"
pre-commit = "^3.6.2"
pytest = "^8.1.1"
pytest-cov = "^4.1.0"

[tool.coverage.run]
omit = [
"scripts/*",
]
branch = true

[build-system]
requires = ["poetry-core"]
Expand Down
39 changes: 39 additions & 0 deletions scripts/runtests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python

import sys
from argparse import ArgumentParser
from pathlib import Path
import pytest


base = Path(__file__).absolute().parent.parent
sys.path.extend([str(base)])


def main():
parser = ArgumentParser("Run unit tests")
parser.add_argument(
"--no-coverage", action="store_true", help="Do not add in coverage options"
)
other_args, pytest_args = parser.parse_known_args()

args = ["--durations=5", "-v", "--tb=short", "--color=yes"]

args.extend(pytest_args)

if all(arg.startswith("-") for arg in pytest_args):
args.append("tests")

has_config = any(arg.startswith("--cov-config") for arg in args)
if not has_config and not other_args.no_coverage:
args.extend(["--cov-config=pyproject.toml", "--cov=."])

print(f"pytest {' '.join(args)}", file=sys.stderr)

return_value = pytest.main(args)

raise SystemExit(return_value)


if __name__ == "__main__":
main()

0 comments on commit 3d12130

Please sign in to comment.