Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for Tavern 2.0+ #8

Merged
merged 14 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .bumpversion.cfg

This file was deleted.

69 changes: 69 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: basic test

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
simple-checks:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- uses: pre-commit/[email protected]

unit-tests:
runs-on: ubuntu-latest
needs: simple-checks

strategy:
fail-fast: false
matrix:
include:
# 'Basic' tests and checks
- TOXENV: py3
TOXCFG: tox.ini

env:
TOXENV: ${{ matrix.TOXENV }}
TOXCFG: ${{ matrix.TOXCFG }}

steps:
- uses: actions/checkout@v4

- uses: actions/cache@v4
env:
cache-name: cache-${{ matrix.TOXENV }}
with:
path: .tox
key: ${{ runner.os }}-tox-${{ env.cache-name }}-${{ hashFiles('pyproject.toml', 'requirements.in') }}

- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml', 'requirements.in') }}
restore-keys: |
${{ runner.os }}-pip-

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: install deps
run: |
pip install uv
uv pip install --system -r constraints.txt

- name: tox
run: |
tox -c ${TOXCFG} -e ${TOXENV}
35 changes: 34 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,37 @@ tags
.pytest_cache

# Sublimetext
*.sublime-*
*.sublime-*

# Vim
*.swp
*.swo

# Pycharm
.idea

# vs
.vs

tavern.lock
pytype_output

.mypy_cache

.vscode

out/
**/*.iml
.idea

allure/

.ijwb/
.pants.d/
.pids/
bazel-bin
bazel-out
bazel-tavern
bazel-testlogs

example/grpc/proto
37 changes: 37 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
- id: pyupgrade
args:
- --py38-plus
files: "tavern/.*"
- repo: https://github.com/rhysd/actionlint
rev: v1.6.27
hooks:
- id: actionlint
args: ["-shellcheck="]
- repo: https://github.com/hadialqattan/pycln
rev: v2.4.0
hooks:
- id: pycln
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.3.4"
hooks:
- id: ruff-format
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0
hooks:
- id: prettier
types_or: [yaml]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
hooks:
- id: mypy
additional_dependencies:
[types-requests, types-protobuf, types-PyYAML, mypy-extensions]
exclude: tests

exclude: (docs/|example/)
11 changes: 0 additions & 11 deletions .pylintrc

This file was deleted.

43 changes: 43 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Contributing

All configuration for the project should be put into `pyproject.toml`.

## Working locally

1. Create a virtualenv using whatever method you like (
eg, [virtualenvwrapper](https://virtualenvwrapper.readthedocs.io/))

1. Install dependencies from requirements.txt

## Updating/adding a dependency

1. Add or update the dependency in [pyproject.toml](/pyproject.toml)

1. Update constraints file

```shell
uv pip compile --all-extras pyproject.toml --output-file constraints.txt -U
```

## Pre-commit

Basic checks (formatting, import order) is done with pre-commit and is controlled by [the yaml file](/.pre-commit-config.yaml).

After installing dependencies, Run

# check it works
pre-commit run --all-files
pre-commit install

Run every so often to update the pre-commit hooks

pre-commit autoupdate

### Fixing Python formatting issue

ruff format tavern/ tests/
ruff --fix tavern/ tests/

### Fix yaml formatting issues

pre-commit run --all-files
138 changes: 138 additions & 0 deletions constraints.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# This file was autogenerated by uv via the following command:
# uv pip compile --all-extras pyproject.toml --output-file constraints.txt
attrs==23.2.0
# via
# jsonschema
# pytest
# referencing
blinker==1.7.0
# via flask
cachetools==5.3.3
# via tox
certifi==2024.2.2
# via requests
cfgv==3.4.0
# via pre-commit
chardet==5.2.0
# via tox
charset-normalizer==3.3.2
# via requests
click==8.1.7
# via flask
colorama==0.4.6
# via tox
colorlog==6.8.2
distlib==0.3.8
# via virtualenv
docopt==0.6.2
# via pykwalify
docutils==0.20.1
# via flit
exceptiongroup==1.2.0
# via pytest
filelock==3.13.3
# via
# tox
# virtualenv
flask==3.0.2
flit==3.9.0
flit-core==3.9.0
# via flit
identify==2.5.35
# via pre-commit
idna==3.6
# via requests
iniconfig==2.0.0
# via pytest
itsdangerous==2.1.2
# via flask
jinja2==3.1.3
# via flask
jmespath==1.0.1
# via tavern
jsonschema==4.21.1
# via tavern
jsonschema-specifications==2023.12.1
# via jsonschema
markupsafe==2.1.5
# via
# jinja2
# werkzeug
nodeenv==1.8.0
# via pre-commit
packaging==24.0
# via
# pyproject-api
# pytest
# tox
paho-mqtt==1.6.1
# via tavern
pbr==6.0.0
# via stevedore
platformdirs==4.2.0
# via
# tox
# virtualenv
pluggy==1.4.0
# via
# pytest
# tox
pre-commit==3.7.0
pyjwt==2.8.0
# via tavern
pykwalify==1.8.0
# via tavern
pyproject-api==1.6.1
# via tox
pytest==7.2.2
# via tavern
python-box==6.1.0
# via tavern
python-dateutil==2.9.0.post0
# via pykwalify
pyyaml==6.0.1
# via
# pre-commit
# tavern
referencing==0.34.0
# via
# jsonschema
# jsonschema-specifications
requests==2.31.0
# via
# flit
# tavern
rpds-py==0.18.0
# via
# jsonschema
# referencing
ruamel-yaml==0.18.6
# via pykwalify
ruamel-yaml-clib==0.2.8
# via ruamel-yaml
ruff==0.3.4
setuptools==69.2.0
# via nodeenv
six==1.16.0
# via python-dateutil
stevedore==4.1.1
# via tavern
tavern==2.10.1
tomli==2.0.1
# via
# pyproject-api
# pytest
# tox
tomli-w==1.0.0
# via flit
tox==4.14.2
urllib3==2.2.1
# via requests
uv==0.1.24
virtualenv==20.25.1
# via
# pre-commit
# tox
werkzeug==3.0.1
# via flask
wheel==0.43.0
9 changes: 0 additions & 9 deletions example/Dockerfile

This file was deleted.

5 changes: 0 additions & 5 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# Example flask server

To run the docker based tests, do:

1. `docker-compose up --build .`
2. `py.test`

To run the tests using tavern-flask, do:

1. `py.test --tavern-http-backend=flask`.
8 changes: 3 additions & 5 deletions example/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
import logging.config

import yaml

from tavern.testutils.pytesthook import YamlItem

from tavern._core.pytest.item import YamlItem

logging_initialised = False

Expand Down Expand Up @@ -39,12 +37,12 @@ def setup_logging():
tavern_flask: *log
"""

as_dict = yaml.load(log_cfg)
as_dict = yaml.load(log_cfg, Loader=yaml.SafeLoader)
logging.config.dictConfig(as_dict)

logging.info("Logging set up")

global logging_initialised
global logging_initialised # noqa
logging_initialised = True


Expand Down
Loading
Loading