Skip to content

update: duration_format renders deprecation warning #589

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

Merged
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
18 changes: 7 additions & 11 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ on:
**
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build_docs:
name: Build Docs
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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' &&
Expand Down
185 changes: 113 additions & 72 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
- 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
- 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

# https://github.com/pytest-dev/pytest-html/issues/585
# - os: macOS-latest
# name: py37-mac
# python-version: 3.7
steps:
- name: Set newline behavior
run: git config --global core.autocrlf false

- tox-env: "py38"
python-version: "3.8"
- uses: actions/checkout@v3

# https://github.com/pytest-dev/pytest-html/issues/585
# - os: windows-latest
# name: py38-windows
# python-version: 3.8
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '16.x'

# https://github.com/pytest-dev/pytest-html/issues/585
# - os: macOS-latest
# name: py38-mac
# python-version: 3.8
- name: Install dependencies
run: npm ci

- tox-env: "py39"
python-version: "3.9"
- name: Build app
run: npm run build:ci

- tox-env: "py310"
python-version: "3.10"
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

# https://github.com/pytest-dev/pytest-html/issues/585
# - os: windows-latest
# name: py39-windows
# python-version: 3.9
- name: Install tox
run: python -m pip install --upgrade tox

# https://github.com/pytest-dev/pytest-html/issues/585
# - os: macOS-latest
# name: py39-mac
# python-version: 3.9
- name: Run unit tests
if: ${{ ! matrix.tox-env && matrix.with-coverage }}
run: tox -e py${{ matrix.python-version }}-cov -- testing/test_unit.py

- tox-env: "pypy3"
python-version: "pypy3.9"
skip-coverage: true
- name: Run unit tests
if: ${{ ! matrix.tox-env && ! matrix.with-coverage }}
run: tox -e py${{ matrix.python-version }} -- testing/test_unit.py

# https://github.com/pytest-dev/pytest-html/issues/585
# - os: windows-latest
# name: pypy3-windows
# python-version: pypy3
- name: Run unit tests
if: ${{ matrix.tox-env }}
run: tox -e ${{ matrix.tox-env }} -- testing/test_unit.py

# https://github.com/pytest-dev/pytest-html/issues/482
# - os: macOS-latest
# name: pypy3-mac
# python-version: pypy-3.8
- 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

- tox-env: "devel"
python-version: "3.11-dev"
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:
- 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
Expand All @@ -84,34 +135,38 @@ 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 }}

- 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
Expand All @@ -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
23 changes: 0 additions & 23 deletions docs/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
12 changes: 8 additions & 4 deletions src/pytest_html/nextgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ def insert(self, index, html):
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": {},
Expand Down Expand Up @@ -84,11 +83,10 @@ def __init__(self, report_path, config, default_css="style.css"):
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):
Expand Down Expand Up @@ -242,6 +240,12 @@ def pytest_collection_finish(self, session):

@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,
Expand Down
5 changes: 0 additions & 5 deletions src/pytest_html/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 26 additions & 0 deletions testing/test_unit.py
Original file line number Diff line number Diff line change
@@ -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'*",
],
)
Loading