Skip to content

Commit

Permalink
Merge pull request #6 from espressif/feat/ignore-no-tests-collected
Browse files Browse the repository at this point in the history
Feat/ignore no tests collected
  • Loading branch information
hfudev authored Feb 3, 2025
2 parents da3858a + e283913 commit 99f08d6
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 106 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
deploy:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand Down
45 changes: 25 additions & 20 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,51 @@ name: Test Python Packages

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
paths:
- "**/*.py"

jobs:
test-build:
timeout-minutes: 10
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.7'
python-version: "3.7"
- run: |
pip install -U pip
pip install flit
flit build
test-package:
timeout-minutes: 10
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.7', '3.11' ]
include:
- python-version: "3.7"
os: ubuntu-20.04
- python-version: "3.13"
os: ubuntu-24.04
fail-fast: false
runs-on: ${{ matrix.os }}
container:
image: python:${{ matrix.python-version }}-bullseye
image: python:${{ matrix.python-version }}
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
pip install pytest pytest-cov
- name: Test with pytest
run: |
pytest --cov pytest_ignore_test_results --cov-report term-missing --cov-report xml --junitxml=results.xml
- name: Pytest coverage comment
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-coverage-path: coverage.xml
junitxml-path: results.xml
- uses: actions/checkout@v3
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
pip install pytest pytest-cov
- name: Test with pytest
run: |
pytest --cov pytest_ignore_test_results --cov-report term-missing --cov-report xml --junitxml=results.xml
- name: Pytest coverage comment
if: ${{ github.event_name == 'pull_request' && matrix.python-version == '3.13' }}
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-coverage-path: coverage.xml
junitxml-path: results.xml
15 changes: 6 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: mixed-line-ending
args: [ '-f=lf' ]
- id: double-quote-string-fixer
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.1
rev: v1.5.5
hooks:
- id: insert-license
files: \.py$
Expand All @@ -17,15 +17,12 @@ repos:
- license_header.txt # defaults to: LICENSE.txt
- --use-current-year
- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 6.0.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.270'
rev: 'v0.9.4'
hooks:
- id: ruff
args: ['--fix']
args: [ '--fix' ]
- id: ruff-format
78 changes: 77 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,79 @@
# pytest-ignore-test-results

A pytest plugin to ignore test results.
A pytest plugin that enables selective test result ignoring while maintaining test execution.

## Installation

```bash
pip install -U pytest-ignore-test-results
```

## Features

- Ignore specific test case results using exact names or patterns
- Load ignore patterns from files
- Custom exit codes for different failure scenarios
- Support for child test cases
- Option to ignore "no tests collected" errors

## Usage

### Ignore Test Results by Case Name or Pattern

When using this plugin, test cases will execute normally but their results can be selectively ignored. You have two options for specifying which test results to ignore:

1. Using exact names or patterns directly:

```bash
pytest --ignore-result-cases "test_feature_1" "test_feature_2"
```

```bash
pytest --ignore-result-cases "test_feature_*" "test_integration_*"
```

2. Specifying patterns in files:

```bash
pytest --ignore-result-files ignore_list.txt another_list.txt
```

Example ignore file content (ignore_list.txt):

```
test_feature_1 # This is a comment
test_feature_*
test_integration_suite::test_case_1
```

### Control Exit Codes

The plugin provides fine-grained control over exit codes through two options:

1. `--strict-exit-code`: When enabled, the plugin will return exit code 6 if all failed test cases are ignored. Otherwise, it maintains pytest's original exit code behavior.

```bash
pytest --ignore-result-cases "test_feature_*" --strict-exit-code
```

2. `--ignore-no-tests-collected`: When enabled, this option suppresses "no tests collected" errors and returns exit code 0.

```bash
pytest --ignore-no-tests-collected
```

### Custom Test Case Names

The plugin supports test case name customization through the `pytest_custom_test_case_name` hook:

```python
def pytest_custom_test_case_name(item):
"""
Args:
item: pytest item
Returns:
str: Custom name for the test case
"""
return f"custom_name::{item.name}"
```
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0

# Configuration file for the Sphinx documentation builder.
Expand All @@ -11,7 +11,7 @@

project = 'pytest-ignore-test-results'
project_homepage = 'https://github.com/espressif/pytest-ignore-test-results'
copyright = '2023, Espressif Systems (Shanghai) Co., Ltd.'
copyright = '2023, Espressif Systems (Shanghai) Co., Ltd.' # noqa
author = 'Fu Hanxi'

# -- General configuration ---------------------------------------------------
Expand Down
81 changes: 28 additions & 53 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ license = {file = "LICENSE"}
classifiers = [
"License :: OSI Approved :: Apache Software License",
"Framework :: Pytest",
"Development Status :: 2 - Pre-Alpha",
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
dynamic = ["version", "description"]
requires-python = ">=3.7"
Expand All @@ -39,6 +41,11 @@ doc = [
"sphinxcontrib-mermaid", # mermaid graph support
]

[project.urls]
Homepage = "https://github.com/espressif/pytest-ignore-test-results"
Repository = "https://github.com/espressif/pytest-ignore-test-results.git"
Changelog = "https://github.com/espressif/pytest-ignore-test-results/blob/main/CHANGELOG.md"

[project.entry-points."pytest11"]
pytest_ignore_test_results = "pytest_ignore_test_results.plugin"

Expand All @@ -52,63 +59,31 @@ version_files = [

[tool.isort]
profile = 'black'
force_grid_wrap = 1

[tool.black]
[tool.ruff]
line-length = 120
target-version = ['py37']
skip-string-normalization = true
target-version = "py37"

[tool.ruff]
[tool.ruff.lint]
select = [
'F', # Pyflakes
'E', # pycodestyle
'W', # pycodestyle
# 'C90', # mccabe
# 'I', # isort
# 'N', # pep8-naming
# 'D', # pydocstyle
# 'UP', # pyupgrade
# 'YTT', # flake8-2020
# 'ANN', # flake8-annotations
# 'S', # flake8-bandit
# 'BLE', # flake8-blind-except
# 'FBT', # flake8-boolean-trap
# 'B', # flake8-bugbear
# 'A', # flake8-builtins
# 'COM', # flake8-commas
# 'C4', # flake8-comprehensions
# 'DTZ', # flake8-datetimez
# 'T10', # flake8-debugger
# 'DJ', # flake8-django
# 'EM', # flake8-errmsg
# 'EXE', # flake8-executable
# 'ISC', # flake8-implicit-str-concat
# 'ICN', # flake8-import-conventions
# 'G', # flake8-logging-format
# 'INP', # flake8-no-pep420
# 'PIE', # flake8-pie
# 'T20', # flake8-print
# 'PYI', # flake8-pyi
# 'PT', # flake8-pytest-style
# 'Q', # flake8-quotes
# 'RSE', # flake8-raise
# 'RET', # flake8-return
# 'SLF', # flake8-self
# 'SIM', # flake8-simplify
# 'TID', # flake8-tidy-imports
# 'TCH', # flake8-type-checking
# 'ARG', # flake8-unused-arguments
# 'PTH', # flake8-use-pathlib
# 'ERA', # eradicate
# 'PD', # pandas-vet
# 'PGH', # pygrep-hooks
# 'PL', # Pylint
# 'TRY', # tryceratops
# 'NPY', # NumPy-specific rules
# 'RUF', # Ruff-specific rules
'F', # Pyflakes
'E', # pycodestyle
'W', # pycodestyle
'I', # isort
'UP', # pyupgrade
'YTT', # flake8-2020
'A', # flake8-builtins
'ARG', # flake8-unused-arguments
'RUF', # ruff
]
line-length = 120
target-version = "py37"

[tool.ruff.lint.flake8-unused-arguments]
ignore-variadic-names = true

[tool.ruff.format]
quote-style = "single"
docstring-code-format = true

[tool.pytest.ini_options]
addopts = "-s"
Loading

0 comments on commit 99f08d6

Please sign in to comment.