diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index a57a1fcc..dc832bc9 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -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' && diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 21eea4a3..c746d7bc 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 @@ -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 diff --git a/docs/user_guide.rst b/docs/user_guide.rst index 57649250..bf0c0f78 100644 --- a/docs/user_guide.rst +++ b/docs/user_guide.rst @@ -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/ diff --git a/src/pytest_html/nextgen.py b/src/pytest_html/nextgen.py index 49feb366..207eb8e2 100644 --- a/src/pytest_html/nextgen.py +++ b/src/pytest_html/nextgen.py @@ -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": {}, @@ -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): @@ -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, diff --git a/src/pytest_html/plugin.py b/src/pytest_html/plugin.py index 2f166c56..4aa3f0d3 100644 --- a/src/pytest_html/plugin.py +++ b/src/pytest_html/plugin.py @@ -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", diff --git a/testing/test_unit.py b/testing/test_unit.py index e69de29b..18ed204a 100644 --- a/testing/test_unit.py +++ b/testing/test_unit.py @@ -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'*", + ], + ) diff --git a/tox.ini b/tox.ini index 3016156a..300ee4ef 100644 --- a/tox.ini +++ b/tox.ini @@ -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]