Skip to content

Commit

Permalink
Merge pull request #3 from CarloDePieri/testing
Browse files Browse the repository at this point in the history
New features:
- `cassette_path_func` the cassettes that are going to be deleted can now be determined by a function that will run after the test is complete, with the test context

Improvement:
- refactor codebase
- improved tooling and code analysis
- add automated release on pypi
  • Loading branch information
CarloDePieri committed Jun 6, 2022
2 parents 13e0ce6 + f7c5557 commit b33926e
Show file tree
Hide file tree
Showing 16 changed files with 1,153 additions and 412 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
name: deploy

on:

release:
types: [published]

jobs:

deploy:
name: deploy
runs-on: ubuntu-latest

steps:

- name: Checkout.
uses: actions/checkout@v2

- uses: actions/setup-python@v3
with:
python-version: '3.7.x'

- name: Make sure path are there also for act shells.
if: ${{ env.ACT }}
run: |
echo "export PATH=\"/opt/hostedtoolcache/Python/${{ env.python_version }}/x64:/opt/hostedtoolcache/Python/${{ env.python_version }}/x64/bin:$PATH\"" >> /root/.bashrc
- name: Upgrade pip.
run: python -m pip install --upgrade pip

- name: Install poetry and invoke.
run: pip install poetry invoke

- name: Configure poetry and pypi
run: |
poetry config virtualenvs.in-project true
# Workaround since it won't take the token auth
poetry config http-basic.pypi "__token__" "${{ secrets.PYPI_TOKEN }}"
- name: Install the first python venv
run: poetry install --no-dev

- name: Build the package
run: inv build

- name: Deploy on pypi
run: poetry publish
27 changes: 25 additions & 2 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
pull_request:
branches:
- "main"
- "testing"

push:
branches:
Expand Down Expand Up @@ -61,6 +62,28 @@ jobs:
- name: Configure poetry
run: poetry config virtualenvs.in-project true

- name: Install dependencies and test for all supported python version
run: inv test-all-python-version
- name: Install the first python venv
run: inv install -p latest

- name: Check formatting
run: inv checks

- name: Launch tests against all supported python versions
run: inv test-all-python-version --coverage

- name: Fix source path in sonarqube coverage file.
if: ${{ !env.ACT }}
run: sed -i "s#`pwd`#/github/workspace#" coverage/sonarqube/coverage.xml

- uses: SonarSource/sonarqube-scan-action@master
if: ${{ !env.ACT }}
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

- uses: CarloDePieri/sonarqube-scan-action@master
if: ${{ env.ACT }}
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

25 changes: 24 additions & 1 deletion .github/workflows/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
if: env.using_act == 'true'
run: |
echo "export PATH=\"/opt/hostedtoolcache/Python/${{ env.python_version }}/x64:/opt/hostedtoolcache/Python/${{ env.python_version }}/x64/bin:$PATH\"" >> /root/.bashrc
- name: Upgrade pip.
run: python -m pip install --upgrade pip

Expand All @@ -61,7 +62,13 @@ jobs:
- name: Configure poetry
run: poetry config virtualenvs.in-project true

- name: Install dependencies and test for all supported python version
- name: Install the first python venv
run: inv install -p latest

- name: Check formatting
run: inv checks

- name: Launch tests against all supported python versions
run: inv test-all-python-version --coverage

- name: Prepare the coveralls config.
Expand All @@ -71,3 +78,19 @@ jobs:
- name: Upload coverage stats
run: inv publish-coverage

- name: Fix source path in sonarqube coverage file.
if: ${{ !env.ACT }}
run: sed -i "s#`pwd`#/github/workspace#" coverage/sonarqube/coverage.xml

- uses: SonarSource/sonarqube-scan-action@master
if: ${{ !env.ACT }}
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

- uses: CarloDePieri/sonarqube-scan-action@master
if: ${{ env.ACT }}
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ coverage
.coveralls.yml
.secrets
dist
.scannerwork/
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![PyPI](https://img.shields.io/pypi/v/pytest-vcr-delete-on-fail)](https://pypi.org/project/pytest-vcr-delete-on-fail/) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pytest-vcr-delete-on-fail)](https://pypi.org/project/pytest-vcr-delete-on-fail/) [![CI Status](https://img.shields.io/github/workflow/status/CarloDePieri/pytest-vcr-delete-on-fail/prod?logo=github)](https://github.com/CarloDePieri/pytest-vcr-delete-on-fail/actions/workflows/prod.yml) [![Coverage Status](https://coveralls.io/repos/github/CarloDePieri/pytest-vcr-delete-on-fail/badge.svg?branch=main)](https://coveralls.io/github/CarloDePieri/pytest-vcr-delete-on-fail?branch=main) [![Maintenance](https://img.shields.io/maintenance/yes/2022)](https://github.com/CarloDePieri/pytest-vcr-delete-on-fail/)
[![PyPI](https://img.shields.io/pypi/v/pytest-vcr-delete-on-fail)](https://pypi.org/project/pytest-vcr-delete-on-fail/) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pytest-vcr-delete-on-fail)](https://pypi.org/project/pytest-vcr-delete-on-fail/) [![CI Status](https://img.shields.io/github/workflow/status/CarloDePieri/pytest-vcr-delete-on-fail/prod?logo=github)](https://github.com/CarloDePieri/pytest-vcr-delete-on-fail/actions/workflows/prod.yml) [![Coverage Status](https://coveralls.io/repos/github/CarloDePieri/pytest-vcr-delete-on-fail/badge.svg?branch=main)](https://coveralls.io/github/CarloDePieri/pytest-vcr-delete-on-fail?branch=main) ![Sonarqube ratings](https://img.shields.io/badge/sonarqube%20ratings-A-success) [![Maintenance](https://img.shields.io/maintenance/yes/2022)](https://github.com/CarloDePieri/pytest-vcr-delete-on-fail/) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

A pytest plugin that automates vcrpy cassettes deletion on test failure.

Expand Down Expand Up @@ -65,6 +65,17 @@ def test_this():
assert False
```

## Targeted pytest version

Pytest internal API can change from major version, so this plugin versions are targeted at specific pytest versions.
Do note that, consequently, plugin features can vary as well between major versions.

| pytest-vcr-delete-on-fail | pytest |
|:-------------------------:|:-------:|
| 1.1.0 | 6.* |

## Advanced usage

The marker is actually quite flexible; this is the full signature:

```python
Expand Down Expand Up @@ -92,6 +103,11 @@ otherwise. If `True` the cassette with the automatically computed path will be d
Only valid as named argument. It's `False` by default. If `True` no cassette will be deleted for that test. It's
equivalent to passing `cassette_path_list=None`.

###### cassette_path_func

A function that takes the `nodes.Item` as only argument and that returns a cassette path or a list of cassette paths
that will be deleted.

### Utilities

When writing a function to determine a cassette path here are some useful imports from `pytest_vcr_delete_on_fail`:
Expand Down Expand Up @@ -147,7 +163,7 @@ To run the test suite against all supported python version (they must be in path
inv test-all-python-version
```

To test the github workflow with [act](https://github.com/nektos/act):
To test the GitHub workflow with [act](https://github.com/nektos/act):

```bash
inv act-dev # test the dev workflow
Expand Down

0 comments on commit b33926e

Please sign in to comment.