DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

How to Generate XML Test Reports in Pytest

Use pytest's built-in JUnit XML option, preserve the report as a CI artifact, and choose report settings that match your consumer.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Generate a JUnit-style XML test report with pytest by adding --junitxml (or --junit-xml) and an output path to your test command:

pytest --junitxml=reports/junit.xml

The report is useful for CI systems and other tools that consume test results. Create the destination directory first if it may not exist, and configure your CI workflow to retain the same file path as an artifact.

Generate the report locally

  1. From your project root, make an output directory if needed:

    mkdir -p reports
  2. Run pytest with the report path:

    pytest --junitxml=reports/junit.xml

    The equivalent spelling --junit-xml is also accepted:

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
    pytest --junit-xml=reports/junit.xml
  3. After pytest finishes, check that reports/junit.xml exists and point your report viewer or CI upload step at that exact path.

The option writes JUnit-style XML; it does not create a missing parent directory for you. If tests fail, pytest can still write a report containing their results, so CI should preserve the file even when the test step exits unsuccessfully.

Keep the XML report in GitHub Actions

Upload the generated file as an artifact so it remains available after the workflow run. The always() condition makes the upload step eligible to run even when the test step fails.

- name: Run tests
  run: pytest tests.py --junitxml=junit/test-results.xml
- name: Upload pytest test results
  if: ${{ always() }}
  uses: actions/upload-artifact@v4
  with:
    name: pytest-results
    path: junit/test-results.xml

This example assumes the junit/ directory exists before pytest runs. In a matrix workflow, use distinct report paths and artifact names per job—for example, include the Python version—to avoid jobs overwriting or colliding with one another.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose report settings deliberately

XML compatibility

Pytest’s junit_family setting accepts legacy, xunit1, and xunit2; xunit2 is the current default. Pytest documentation identifies Jenkins with its JUnit plugin and Azure Pipelines as known xunit2 consumers, but compatibility depends on the actual CI product, plugin, and versions in use. Check the receiving environment before changing the family or relying on a particular parser.

Suite name

junit_suite_name sets the root suite name in the XML. Its documented default is pytest. Set it in pytest configuration if downstream reporting expects a particular suite label.

Reported durations

junit_duration_report defaults to total, which includes setup, test call, and teardown. Set it to call when the report should show only the test function’s call time. These values measure different portions of execution and should not be compared as if they were interchangeable.

Captured output

junit_logging controls whether captured logging, standard output, standard error, or combinations are included; its default is no. The junit_log_passing_tests option controls whether output from passing tests is included when logging is enabled. Including more captured output can make reports larger and noisier, so enable it when that information is useful to the workflow.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Custom XML properties

Pytest warns that record_property and record_xml_attribute can make output fail validation against the latest JUnit XML schema. Check your report consumer’s schema requirements before adding custom properties or attributes. The session-scoped record_testsuite_property fixture is documented as compatible with the latest xunit standard.

Configure settings persistently

Put options that should apply to every run in your pytest configuration file rather than repeating them on the command line. For example, in pytest.ini:

[pytest]
junit_family = xunit2
junit_suite_name = project-tests
junit_duration_report = total

Use only settings your project needs. For instance, retain the default family unless your report consumer requires another format, and choose call instead of total only when excluding setup and teardown time is intentional.

Troubleshoot missing or unusable reports

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

For a separate task—capturing a web page as an image or PDF rather than generating pytest’s test-results XML—ScreenshotNeo offers a single-request screenshot API. This does not replace pytest’s JUnit report option.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. Before a screenshot, it can accept consent banners and remove known consent platforms, newsletter popups, and chat widgets; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. ScreenshotNeo also has an MCP server for AI agents, with tools for screenshots, page information, and PDF capture. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. See ScreenshotNeo for product details. Sign up free for 1,000 screenshots a month, with no card required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

Can pytest write a JUnit XML report if some tests fail?

Yes. Pytest’s report is intended to contain test results, including failures; the test command can still return a failing exit status.

Does generating a JUnit XML report require an extra pytest plugin?

The built-in pytest command-line option is sufficient; use `–junitxml=PATH` or `–junit-xml=PATH`.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.