# Update Pytest to Generate JUnit XML for Import into Testery

### Step 1: Install the pytest-xdist Plugin

To generate JUnit XML reports for your Pytest tests, you'll need to install the `pytest-xdist` plugin. This plugin extends Pytest's functionality and provides the JUnit XML report generation feature.

Open your project's terminal and run the following command to install the plugin:

```bash
pip install pytest-xdist
```

### Step 2: Update Your Pytest Configuration

Now that you have the `pytest-xdist` plugin installed, you need to update your Pytest configuration to use it.

1. Create a Pytest configuration file, if you don't already have one. The configuration file should be named `pytest.ini` or `pyproject.toml` (for newer Pytest versions).
2. Add the following configuration to enable the JUnit XML report generation:

   For `pytest.ini`:

   ```ini
   [pytest]
   junit_family = xunit2
   junit_suite_name = Your_Test_Suite_Name
   junit_logging = all
   junit_log_passing_tests = True
   junit_log_truncate = True
   ```

   Replace `Your_Test_Suite_Name` with an appropriate name for your test suite.

   For `pyproject.toml`:

   ```ini
   [tool.pytest.ini_options]
   junit_family = 'xunit2'
   junit_suite_name = 'Your_Test_Suite_Name'
   junit_logging = 'all'
   junit_log_passing_tests = true
   junit_log_truncate = true
   ```

   Again, replace `Your_Test_Suite_Name` as needed.

### Step 3: Run Your Pytest Tests

With your Pytest configuration updated, you can now run your tests as usual. Pytest will automatically use the JUnit XML reporter to generate XML reports.

To run your tests, use the following command:

```bash
pytest
```

After running the tests, you should see JUnit XML files generated in your project directory.

### Step 4: Upload Your Test Results to Testery

The final step is to upload the generated JUnit XML files to Testery for further analysis. You can use the Testery CLI to achieve this. Ensure you have the Testery CLI installed:

```bash
pip install testery
```

Once installed, you can use the following command to upload your test results to Testery:

```bash
testery upload-results \
  --environment develop \
  --project Your_Project_Name \
  --file junit.xml
```

Replace `Your_Project_Name` with your specific project name and adjust the `--file` option to point to the location of your JUnit XML files generated by Pytest.

This step will make your Pytest test results accessible within Testery, allowing you to monitor and analyze them efficiently.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.testery.io/framework-specific-guidance/pytest/update-pytest-to-generate-junit-xml-for-import-into-testery.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
