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

Simplify usage of plugin #1

Merged
merged 7 commits into from
Jan 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
26 changes: 0 additions & 26 deletions .github/workflows/build-release.yml

This file was deleted.

94 changes: 94 additions & 0 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Publish Python 🐍 distribution 📦 to PyPI

on: push

jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"

- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/')
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/pytest-slow-first
permissions:
id-token: write

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
needs:
- publish-to-pypi
runs-on: ubuntu-latest

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/gh-action-sigstore-python@v1.2.3
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ __pycache__/

# C extensions
*.so

.idea/
# Distribution / packaging
.Python
env/
Expand Down
3 changes: 0 additions & 3 deletions .idea/.gitignore

This file was deleted.

19 changes: 0 additions & 19 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

4 changes: 0 additions & 4 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/pytest-slow-first.iml

This file was deleted.

42 changes: 4 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,44 +39,6 @@ In the next time you run it, tests will be sorted by time spend in the last run,
</br>
</hr>

Usage
-----

You just need to define two functions inside your conftest.py file: `slow_first_save_durations` and `slow_first_load_durations`.

The first one is to save results of current run and the second one is to load the same results in the folowing run. Allowing this plugin to sort execuntion of tests based in these results.

Example of `conftest.py` file:
```python
import os, json


def slow_first_load_durations():
if os.path.exists('/tmp/tests_duration'):
with open('/tmp/tests_duration', 'r') as f:
return f.read()
else:
# Durations not found. Run with default order
return None

def slow_first_save_durations(durations_data: str):
with open('/tmp/tests_duration', 'w') as f:
f.write(durations_data)
```

#### Explanation

1. First, `slow_first_load_durations` will be called before your tests starts running, it will load the durantion of the tests
of the previous run.

* **obs**: if its the first time using this plugin or if you can't load the results, this function must return None.

2. If `slow_first_load_durations` finds data, it returns the content and slow-first plugin will sort your tests, otherwise
the test suite will run at default order.

3. If the suit runs with success, `slow_first_save_durations` is going to be called with durations as argument. This function must save the results
in a way that `slow_first_load_durations` can load in the next run.

### Running with pytest-slow-first plugin
Finally, activate the plugin by passing `--slow-first` as paramter of pytest command:

Expand All @@ -87,6 +49,10 @@ pytest tests --slow-first -n3 # using along side xdist
</br>
</hr>

THis plugin will save the duration of each of your tests in a file named `pytest-slow-first.json` in the current directory.
You can change the location by setting the enviroment variable `SLOW_FIRST_PATH` to the path you want.
Ex: `export SLOW_FIRST_PATH=/tmp/pytest-slow-first.json pytest --slow-first`

Installation
------------

Expand Down
Loading
Loading