Skip to main content
PyPI version Python versions See Build Status on Travis CI See Build Status on AppVeyor

English | 简体中文

pytest-upload-report is a plugin for pytest that upload your test report for test results.

Features

  • Upload report for allure-pytest.

  • Upload report for pytest-html.

Requirements

  • Python >= 3.7

  • pytest

  • requests

  • allure-pytest, if you use allure report.

  • pytest-html, if you use html report.

Installation

You can install “pytest-upload-report” via pip from PyPI:

$ pip install pytest-upload-report

Usage

A simple example

Directly upload report files to server by upload_url.

On the command line, add upload_url option when run pytest command:

pytest --alluredir=/tmp/my_allure_results --upload_url=http://127.0.0.1:8000/upload

A complete example

Now let us demonstrate how to use in a vaguely real world scenario.

First, you must have a upload api on server, an example for fastapi:

from fastapi import APIRouter, UploadFile, File, Header

router = APIRouter(prefix='/api/script', tags=['script'])

@router.post("/reports/upload")
async def report_upload_by_api(
    project_id: int,
    timestamp: int,
    username: str,
    sign: str = Header(...),
    files: List[UploadFile] = File(...),
):
    ...
    return 'ok'

Second, edit your conftest.py file, add pytest_send_upload_request hook:

import pytest

@pytest.hookimpl(tryfirst=True)
def pytest_send_upload_request(upload_url, files, config):
    from pytest_upload_report.upload_client import SignUploadClient
    client = SignUploadClient(upload_url, files)
    client.send_request(config)
    return True

The other hooks will be blocked from executing, when then hook return True. If you want to upload multiple places, don’t write any return.

Third, edit pytest.init on you test project root dir:

[pytest]
addopts = --alluredir=/tmp/my_allure_results --upload_url=http://127.0.0.1:8000/api/script/reports/upload --upload_project_id=4 --upload_username=admin --upload_secret=8FB6CFB4C8CF11EBB523DCA9048E18C3

Finally, run pytest command on you test project root dir:

$ pytest

Also, you can view source code in the example directory.

How to Customize

If the above does not meet your needs, you can customize request client.

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the MIT license, “pytest-upload-report” is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.

Release files for pytest-upload-report 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-upload-report 0.1.0
File Size Uploaded
pytest-upload-report-0.1.0.tar.gz 6.7 kB Details

Release files / pytest-upload-report-0.1.0.tar.gz

Download URL pytest-upload-report-0.1.0.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
350b7d375f8715f15c5589a4e4f2c9c034905c47a0c8ac640fb3adf95f0e086d
BLAKE2b-256 checksum
How to use checksums
6444090eb55a5c54ebf504a372be1bef887e7db799beaba8ee15fe49dff7ad8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page