update: duration_format renders deprecation warning (#589)

This commit is contained in:
Jim Brännlund 2023-03-19 16:15:16 +01:00 committed by GitHub
parent df894ec408
commit d02dac0dda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 167 additions and 128 deletions

View File

@ -13,6 +13,10 @@ on:
**
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build_docs:
name: Build Docs
@ -40,14 +44,11 @@ jobs:
env:
PY_COLORS: 1
steps:
- name: Switch to using Python 3.10 by default
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install tox
run: python -m pip install --user tox
- name: Check out src from Git
uses: actions/checkout@v3
with:
@ -69,10 +70,7 @@ jobs:
if: >-
github.event_name != 'create' ||
github.event.ref_type != 'tag'
run: >-
git tag --points-at HEAD
|
xargs git tag --delete
run: git tag --points-at HEAD | xargs git tag --delete
- name: Build and Check Package
uses: hynek/build-and-inspect-python-package@v1
@ -87,9 +85,7 @@ jobs:
if: >-
(
github.event_name == 'push' &&
github.ref == format(
'refs/heads/{0}', github.event.repository.default_branch
)
github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
) ||
(
github.event_name == 'create' &&

View File

@ -4,74 +4,125 @@ on:
workflow_call:
jobs:
test_python:
name: ${{ matrix.python-version }}
test_javascript:
name: javascript
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '16.x'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm run unit
test_unit:
name: ${{ matrix.os }} - ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.7", "3.8", "3.9", "3.10"]
include:
- os: ubuntu-latest
python-version: "3.10"
with-coverage: true
- os: ubuntu-latest
python-version: pypy3.9
tox-env: py3.9
- os: windows-latest
python-version: pypy3.9
tox-env: py3.9
- os: macos-latest
python-version: pypy3.9
tox-env: py3.9
- os: ubuntu-latest
python-version: 3.11-dev
tox-env: devel
- os: windows-latest
python-version: 3.11-dev
tox-env: devel
- os: macos-latest
python-version: 3.11-dev
tox-env: devel
steps:
- name: Set newline behavior
run: git config --global core.autocrlf false
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '16.x'
- name: Install dependencies
run: npm ci
- name: Build app
run: npm run build:ci
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install tox
run: python -m pip install --upgrade tox
- name: Run unit tests
if: ${{ ! matrix.tox-env && matrix.with-coverage }}
run: tox -e py${{ matrix.python-version }}-cov -- testing/test_unit.py
- name: Run unit tests
if: ${{ ! matrix.tox-env && ! matrix.with-coverage }}
run: tox -e py${{ matrix.python-version }} -- testing/test_unit.py
- name: Run unit tests
if: ${{ matrix.tox-env }}
run: tox -e ${{ matrix.tox-env }} -- testing/test_unit.py
- name: Upload coverage to codecov
if: >-
${{
! github.event.schedule &&
matrix.with-coverage &&
github.repository_owner == 'pytest-dev'
}}
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
files: ./coverage.xml
flags: tests
name: ${{ matrix.os }}-${{ matrix.python-version }}
verbose: true
test_integration:
name: ubuntu - ${{ matrix.python-version }}
needs:
- test_javascript
- test_unit
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
include:
- tox-env: "py37"
python-version: "3.7"
# https://github.com/pytest-dev/pytest-html/issues/585
# - os: windows-latest
# name: py37-windows
# python-version: 3.7
# https://github.com/pytest-dev/pytest-html/issues/585
# - os: macOS-latest
# name: py37-mac
# python-version: 3.7
- tox-env: "py38"
python-version: "3.8"
# https://github.com/pytest-dev/pytest-html/issues/585
# - os: windows-latest
# name: py38-windows
# python-version: 3.8
# https://github.com/pytest-dev/pytest-html/issues/585
# - os: macOS-latest
# name: py38-mac
# python-version: 3.8
- tox-env: "py39"
python-version: "3.9"
- tox-env: "py310"
python-version: "3.10"
# https://github.com/pytest-dev/pytest-html/issues/585
# - os: windows-latest
# name: py39-windows
# python-version: 3.9
# https://github.com/pytest-dev/pytest-html/issues/585
# - os: macOS-latest
# name: py39-mac
# python-version: 3.9
- tox-env: "pypy3"
python-version: "pypy3.9"
skip-coverage: true
# https://github.com/pytest-dev/pytest-html/issues/585
# - os: windows-latest
# name: pypy3-windows
# python-version: pypy3
# https://github.com/pytest-dev/pytest-html/issues/482
# - os: macOS-latest
# name: pypy3-mac
# python-version: pypy-3.8
- tox-env: "devel"
python-version: "3.11-dev"
- python-version: "3.10"
with-coverage: true
- python-version: pypy3.9
tox-env: py3.9
- python-version: 3.11-dev
tox-env: devel
steps:
- name: Set Newline Behavior
- name: Set newline behavior
run: git config --global core.autocrlf false
- uses: actions/checkout@v3
@ -84,13 +135,13 @@ jobs:
with:
node-version: '16.x'
- name: Install Dependencies
- name: Install dependencies
run: npm ci
- name: Build app
run: npm run build:ci
- name: Set up Python
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
@ -98,20 +149,24 @@ jobs:
- name: Install tox
run: python -m pip install --upgrade tox
- name: Test with coverage
if: ${{ ! matrix.skip-coverage }}
run: tox -e ${{ matrix.tox-env }}-cov
- name: Run integration tests
if: ${{ ! matrix.tox-env && matrix.with-coverage }}
run: tox -e ${{ matrix.python-version }}-cov -- testing/test_integration.py
- name: Test without coverage
if: ${{ matrix.skip-coverage }}
run: tox -e ${{ matrix.tox-env }}
- name: Run integration tests
if: ${{ ! matrix.tox-env && ! matrix.with-coverage }}
run: tox -e ${{ matrix.python-version }} -- testing/test_integration.py
- name: Run integration tests
if: ${{ matrix.tox-env }}
run: tox -e ${{ matrix.tox-env }} -- testing/test_integration.py
# TODO: https://github.com/pytest-dev/pytest-html/issues/481
- name: Upload coverage to codecov
if: >-
${{
! github.event.schedule &&
! matrix.skip-coverage &&
matrix.with-coverage &&
github.repository_owner == 'pytest-dev'
}}
uses: codecov/codecov-action@v3
@ -121,17 +176,3 @@ jobs:
flags: tests
name: ${{ matrix.tox-env }}
verbose: true
test_javascript:
name: mocha
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '16.x'
- name: Install Dependencies
run: npm ci
- name: Mocha Tests
run: npm run unit

View File

@ -281,29 +281,6 @@ The following query parameters may be passed:
* :code:`xpassed`
* :code:`rerun`
Formatting the Duration Column
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The formatting of the timestamp used in the :code:`Durations` column can be modified by setting :code:`duration_formatter`
on the :code:`report` attribute. All `time.strftime`_ formatting directives are supported. In addition, it is possible
to supply :code:`%f` to get duration milliseconds. If this value is not set, the values in the :code:`Durations` column are
displayed in :code:`%S.%f` format where :code:`%S` is the total number of seconds a test ran for.
Below is an example of a :code:`conftest.py` file setting :code:`duration_formatter`:
.. code-block:: python
import pytest
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
setattr(report, "duration_formatter", "%H:%M:%S.%f")
**NOTE**: Milliseconds are always displayed with a precision of 2
.. _@pytest.hookimpl(tryfirst=True): https://docs.pytest.org/en/stable/writing_plugins.html#hook-function-ordering-call-example
.. _ansi2html: https://pypi.python.org/pypi/ansi2html/
.. _Content Security Policy (CSP): https://developer.mozilla.org/docs/Web/Security/CSP/

View File

@ -45,12 +45,11 @@ class BaseReport:
self._html[index] = html
class Report:
def __init__(self, title, duration_format):
def __init__(self, title):
self._data = {
"title": title,
"collectedItems": 0,
"runningState": "not_started",
"durationFormat": duration_format,
"environment": {},
"tests": [],
"resultsTableHeader": {},
@ -84,11 +83,10 @@ class BaseReport:
self._css = _process_css(
Path(self._resources_path, default_css), self._config.getoption("css")
)
self._duration_format = config.getini("duration_format")
self._max_asset_filename_length = int(
config.getini("max_asset_filename_length")
)
self._report = self.Report(self._report_path.name, self._duration_format)
self._report = self.Report(self._report_path.name)
@property
def css(self):
@ -242,6 +240,12 @@ class BaseReport:
@pytest.hookimpl(trylast=True)
def pytest_runtest_logreport(self, report):
if hasattr(report, "duration_formatter"):
warnings.warn(
"'duration_formatter' has been removed and no longer has any effect!",
DeprecationWarning,
)
data = {
"duration": report.duration,
"when": report.when,

View File

@ -42,11 +42,6 @@ def pytest_addoption(parser):
default=[],
help="append given css file content to report style file.",
)
parser.addini(
"duration_format",
default=None,
help="the format for duration.",
)
parser.addini(
"render_collapsed",
type="bool",

View File

@ -0,0 +1,26 @@
pytest_plugins = ("pytester",)
def run(pytester, path="report.html", *args):
path = pytester.path.joinpath(path)
return pytester.runpytest("--html", path, *args)
def test_duration_format_deprecation_warning(pytester):
pytester.makeconftest(
"""
import pytest
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
setattr(report, "duration_formatter", "%H:%M:%S.%f")
"""
)
pytester.makepyfile("def test_pass(): pass")
result = run(pytester)
result.stdout.fnmatch_lines(
[
"*DeprecationWarning: 'duration_formatter'*",
],
)

View File

@ -4,7 +4,7 @@
# and then run "tox" from this directory.
[tox]
envlist = py{37,38,39,310,py3}, docs, linting
envlist = py{3.7, 3.8, 3.9, 3.10, py3.9}, docs, linting
isolated_build = True
[testenv]