Skip to content

fix: make pytest basetemp unique per session to prevent cross-session conflicts - #387

Merged
myakove merged 2 commits into
RedHatQE:mainfrom
krcmarik:basetemp
Mar 25, 2026
Merged

myakove merged 2 commits into
RedHatQE:mainfrom
krcmarik:basetemp

Conversation

@krcmarik

@krcmarik krcmarik commented Mar 25, 2026 •

Copy link
Copy Markdown
Collaborator

The fixed --basetemp=/tmp/pytest was shared across all test sessions. When multiple sessions ran in parallel, one session's teardown (shutil.rmtree) could delete another session's temp files (e.g., SSL cert files).

Each session now gets a unique basetemp via pytest_configure hook.

Summary by CodeRabbit

  • Chores
    • Test runs now use a session-unique temporary directory by default, improving isolation and avoiding conflicts; the previous hardcoded base-temp setting was removed.
  • Documentation
    • Updated docs and examples to remove the fixed base-temp setting and reflect that the base temp is auto-generated per test session (can still be overridden).

@qodo-code-review

Copy link
Copy Markdown
ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan

Review Summary by Qodo

Make pytest basetemp unique per session to prevent conflicts

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Prevent cross-session temp file conflicts by generating unique basetemp
• Remove hardcoded basetemp from pytest.ini configuration
• Implement pytest_configure hook to assign unique directory per session
• Use UUID suffix to ensure isolation between parallel test sessions
Diagram
flowchart LR
  A["pytest.ini<br/>hardcoded basetemp"] -->|removed| B["pytest_configure hook"]
  B -->|generates unique| C["basetemp with UUID"]
  C -->|prevents| D["cross-session conflicts"]
Loading

Grey Divider

File Changes

1. conftest.py 🐞 Bug fix +11/-0

Add pytest_configure hook for unique basetemp

• Added uuid import for generating unique identifiers
• Implemented pytest_configure hook to dynamically set unique basetemp per session
• Hook generates basetemp path with UUID suffix only if not already configured
• Ensures each parallel test session gets isolated temporary directory

conftest.py


2. pytest.ini ⚙️ Configuration changes +0/-1

Remove hardcoded basetemp configuration

• Removed hardcoded --basetemp=/tmp/pytest configuration option
• Allows dynamic basetemp assignment via pytest_configure hook instead

pytest.ini


Grey Divider

Qodo Logo

@coderabbitai

coderabbitai Bot commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

A new pytest hook in conftest.py auto-generates a session-unique basetemp (format: .../pytest-<8-hex-uuid>) when --basetemp is not provided. The repository-wide explicit --basetemp=/tmp/pytest settings were removed from pytest.ini and documentation snippets.

Changes

Cohort / File(s) Summary
Runtime hook
conftest.py
Added pytest_configure(config: pytest.Config) -> None which sets config.option.basetemp to a session-unique temp directory when unset (uses uuid to generate an 8-hex fragment).
Project config
pytest.ini
Removed the explicit --basetemp=/tmp/pytest from addopts, deferring to hook or user-provided --basetemp.
Documentation updates
docs/.../automation-and-release.md, docs/.../container-and-openshift-job-execution.md, docs/.../development-workflow.md, docs/.../introduction.md, docs/.../optional-integrations-and-secrets.md, docs/.../project-structure.md, docs/.../pytest-options-and-markers.md, docs/.../quickstart-first-run.md, docs/.../runtime-configuration.md, docs/.../troubleshooting-and-diagnostics.md
Removed references to --basetemp=/tmp/pytest; updated docs to reflect that basetemp is now auto-generated per session (and can still be overridden via --basetemp=/path).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: making pytest basetemp unique per session to prevent conflicts, which is the core fix across all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@qodo-code-review

qodo-code-review Bot commented Mar 25, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (5) 📘 Rule violations (0) 📎 Requirement gaps (0) 📐 Spec deviations (0)

Grey Divider


Action required

1. Hardcoded /tmp basetemp 🐞 Bug ⛯ Reliability
Description
pytest_configure sets config.option.basetemp to a /tmp/... path, which is not portable and
will fail on native Windows runs. This also ignores the existing repo pattern of using
tempfile.gettempdir() for temp locations.
Code

conftest.py[R123-130]

+def pytest_configure(config: pytest.Config) -> None:
+    """Set a unique basetemp directory per session to prevent cross-session conflicts.
+
+    Args:
+        config (pytest.Config): Pytest configuration object used to set basetemp.
+    """
+    if config.option.basetemp is None:
+        config.option.basetemp = f"/tmp/pytest-{uuid.uuid4().hex[:8]}"
Evidence
The new hook hardcodes /tmp for basetemp. The project explicitly documents Windows usage, and the
same conftest already uses tempfile.gettempdir() for a shared temp directory, indicating temp root
should be platform-derived rather than hardcoded.

conftest.py[123-131]
README.md[12-18]
conftest.py[561-568]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`pytest_configure` hardcodes `/tmp/...` for `basetemp`, which breaks native Windows and is inconsistent with existing `tempfile.gettempdir()` usage.
### Issue Context
The repo documentation mentions Windows users. Other temp paths (e.g., virtctl cache dir) are derived from `tempfile.gettempdir()`.
### Fix Focus Areas
- conftest.py[123-131]
### Implementation notes
- Replace `"/tmp/..."` with something like:
- `base = Path(tempfile.gettempdir())`
- `config.option.basetemp = str(base / f"pytest-{uuid.uuid4().hex}")`
- Keep behavior of only setting when `config.option.basetemp is None`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Unconditional basetemp rmtree 🐞 Bug ⛨ Security
Description
Session teardown unconditionally deletes session.config.option.basetemp, so any user-provided
--basetemp (or an unexpectedly broad value) will be removed at the end of the run. This is a
data-loss footgun and is now more likely because this PR intentionally manipulates basetemp at
runtime.
Code

conftest.py[R129-130]

+    if config.option.basetemp is None:
+        config.option.basetemp = f"/tmp/pytest-{uuid.uuid4().hex[:8]}"
Evidence
The new code only sets basetemp when it is None, meaning a user-supplied --basetemp will
persist. The sessionfinish hook then always calls shutil.rmtree() on that value, which can delete
arbitrary directories if misconfigured or if a user set --basetemp for debugging/persistence.

conftest.py[123-131]
conftest.py[233-260]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`pytest_sessionfinish` always deletes `session.config.option.basetemp`. With the new `pytest_configure` behavior (only setting basetemp when None), a user-provided `--basetemp` can be deleted, creating a data-loss risk.
### Issue Context
The PR’s goal is cross-session isolation, but cleanup must not remove arbitrary user-selected paths.
### Fix Focus Areas
- conftest.py[123-131]
- conftest.py[233-260]
### Implementation notes
- Track whether basetemp was auto-generated, e.g.:
- in `pytest_configure`, when you set `config.option.basetemp`, also set `config._mtv_generated_basetemp = True`.
- if basetemp is already set, set the flag to False.
- In `pytest_sessionfinish`, only `rmtree()` when the flag is True.
- Additionally, defensively validate the path before deleting:
- ensure it is inside `tempfile.gettempdir()` (resolve/realpath check)
- ensure it matches your expected prefix (e.g., `pytest-`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

3. Non-atomic basetemp creation 🐞 Bug ⛯ Reliability
Description
The new basetemp is derived from uuid.uuid4().hex[:8] and assigned without creating the directory,
so (rare) collisions or pre-existing directories can still cause cross-session sharing. This
partially undermines the PR’s stated goal of preventing cross-session conflicts.
Code

conftest.py[R129-130]

+    if config.option.basetemp is None:
+        config.option.basetemp = str(Path(tempfile.gettempdir()) / f"pytest-{uuid.uuid4().hex[:8]}")
Evidence
pytest_configure sets basetemp to .../pytest- (32 bits of entropy) and does not ensure the
directory is newly created and unique (no mkdtemp, no existence check). If the directory already
exists or collides, multiple sessions can land in the same basetemp again, reintroducing the
conflict the PR is trying to eliminate.

conftest.py[123-131]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Basetemp is generated as a plain string with truncated UUID entropy and no atomic directory creation.
### Issue Context
The PR goal is to prevent cross-session conflicts; guaranteeing uniqueness via atomic creation is the safest approach.
### Fix Focus Areas
- conftest.py[123-131]
### Implementation notes
- Replace the string composition with `tempfile.mkdtemp(prefix="pytest-")` (optionally under `tempfile.gettempdir()`), and assign that returned path to `config.option.basetemp`.
- If you want deterministic cleanup, pair this with an ownership flag so the suite deletes only directories it created.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Docs suggest fixed basetemp 🐞 Bug ⚙ Maintainability
Description
Documentation still shows --basetemp=/tmp/pytest, which reintroduces the cross-session conflict
this PR is fixing and no longer matches pytest.ini. Users following docs will likely bring the
original race back.
Code

pytest.ini[11]

-  --basetemp=/tmp/pytest
Evidence
pytest.ini removed the fixed basetemp option, but docs still present it as a default/addopt and
explain it as a fixed temp root. That guidance conflicts with the new design and will cause users to
recreate the shared directory problem.

pytest.ini[4-14]
docs/pytest-options-and-markers.md[21-59]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Docs still instruct `--basetemp=/tmp/pytest`, which undermines this PR’s fix and is inconsistent with `pytest.ini`.
### Issue Context
This PR removed the ini-level fixed basetemp and introduced per-session basetemp via `pytest_configure`.
### Fix Focus Areas
- docs/pytest-options-and-markers.md[21-59]
- (Optionally) other docs pages that embed the same `pytest.ini` snippet
### Implementation notes
- Remove or update `--basetemp=/tmp/pytest` in documentation snippets.
- Replace the explanation bullet to describe the new behavior (unique per session), and document how to override `--basetemp` safely if needed.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. Short basetemp suffix 🐞 Bug ⛯ Reliability
Description
The generated basetemp uses only 8 hex characters of UUID (32 bits), which can collide under high
fan-out CI and reintroduce cross-session deletion conflicts. Using the full UUID (or more entropy)
eliminates this avoidable risk.
Code

conftest.py[130]

+        config.option.basetemp = f"/tmp/pytest-{uuid.uuid4().hex[:8]}"
Evidence
The code explicitly truncates uuid4().hex to 8 characters, limiting the namespace to 2^32
possibilities. Collisions are low probability but directly map back to the same failure mode (shared
basetemp and teardown deleting another run’s temp files).

conftest.py[129-130]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Basetemp uniqueness is limited by truncating UUID to 8 hex chars.
### Issue Context
This PR’s purpose is to avoid shared basetemp across sessions; collisions (even rare) are the same class of failure.
### Fix Focus Areas
- conftest.py[129-130]
### Implementation notes
- Use `uuid.uuid4().hex` without truncation, or include PID/time to increase entropy.
- Keep the directory name reasonably sized; full UUID is still short enough for paths.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Grey Divider

Previous review results

Review updated until commit 3920879

Results up to commit 3920879


🐞 Bugs (5) 📘 Rule violations (0) 📎 Requirement gaps (0) 📐 Spec deviations (0)

Grey Divider
Action required
1. Hardcoded /tmp basetemp 🐞 Bug ⛯ Reliability
Description
pytest_configure sets config.option.basetemp to a /tmp/... path, which is not portable and
will fail on native Windows runs. This also ignores the existing repo pattern of using
tempfile.gettempdir() for temp locations.
Code

conftest.py[R123-130]

+def pytest_configure(config: pytest.Config) -> None:
+    """Set a unique basetemp directory per session to prevent cross-session conflicts.
+
+    Args:
+        config (pytest.Config): Pytest configuration object used to set basetemp.
+    """
+    if config.option.basetemp is None:
+        config.option.basetemp = f"/tmp/pytest-{uuid.uuid4().hex[:8]}"
Evidence
The new hook hardcodes /tmp for basetemp. The project explicitly documents Windows usage, and the
same conftest already uses tempfile.gettempdir() for a shared temp directory, indicating temp root
should be platform-derived rather than hardcoded.

conftest.py[123-131]
README.md[12-18]
conftest.py[561-568]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`pytest_configure` hardcodes `/tmp/...` for `basetemp`, which breaks native Windows and is inconsistent with existing `tempfile.gettempdir()` usage.
### Issue Context
The repo documentation mentions Windows users. Other temp paths (e.g., virtctl cache dir) are derived from `tempfile.gettempdir()`.
### Fix Focus Areas
- conftest.py[123-131]
### Implementation notes
- Replace `"/tmp/..."` with something like:
- `base = Path(tempfile.gettempdir())`
- `config.option.basetemp = str(base / f"pytest-{uuid.uuid4().hex}")`
- Keep behavior of only setting when `config.option.basetemp is None`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Unconditional basetemp rmtree 🐞 Bug ⛨ Security
Description
Session teardown unconditionally deletes session.config.option.basetemp, so any user-provided
--basetemp (or an unexpectedly broad value) will be removed at the end of the run. This is a
data-loss footgun and is now more likely because this PR intentionally manipulates basetemp at
runtime.
Code

conftest.py[R129-130]

+    if config.option.basetemp is None:
+        config.option.basetemp = f"/tmp/pytest-{uuid.uuid4().hex[:8]}"
Evidence
The new code only sets basetemp when it is None, meaning a user-supplied --basetemp will
persist. The sessionfinish hook then always calls shutil.rmtree() on that value, which can delete
arbitrary directories if misconfigured or if a user set --basetemp for debugging/persistence.

conftest.py[123-131]
conftest.py[233-260]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`pytest_sessionfinish` always deletes `session.config.option.basetemp`. With the new `pytest_configure` behavior (only setting basetemp when None), a user-provided `--basetemp` can be deleted, creating a data-loss risk.
### Issue Context
The PR’s goal is cross-session isolation, but cleanup must not remove arbitrary user-selected paths.
### Fix Focus Areas
- conftest.py[123-131]
- conftest.py[233-260]
### Implementation notes
- Track whether basetemp was auto-generated, e.g.:
- in `pytest_configure`, when you set `config.option.basetemp`, also set `config._mtv_generated_basetemp = True`.
- if basetemp is already set, set the flag to False.
- In `pytest_sessionfinish`, only `rmtree()` when the flag is True.
- Additionally, defensively validate the path before deleting:
- ensure it is inside `tempfile.gettempdir()` (resolve/realpath check)
- ensure it matches your expected prefix (e.g., `pytest-`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
3. Non-atomic basetemp creation 🐞 Bug ⛯ Reliability ⭐ New
Description
The new basetemp is derived from uuid.uuid4().hex[:8] and assigned without creating the directory,
so (rare) collisions or pre-existing directories can still cause cross-session sharing. This
partially undermines the PR’s stated goal of preventing cross-session conflicts.
Code

conftest.py[R129-130]

+    if config.option.basetemp is None:
+        config.option.basetemp = str(Path(tempfile.gettempdir()) / f"pytest-{uuid.uuid4().hex[:8]}")
Evidence
pytest_configure sets basetemp to .../pytest-<8 hex chars> (32 bits of entropy) and does not
ensure the directory is newly created and unique (no mkdtemp, no existence check). If the
directory already exists or collides, multiple sessions can land in the same basetemp again,
reintroducing the conflict the PR is trying to eliminate.

conftest.py[123-131]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
Basetemp is generated as a plain string with truncated UUID entropy and no atomic directory creation.

### Issue Context
The PR goal is to prevent cross-session conflicts; guaranteeing uniqueness via atomic creation is the safest approach.

### Fix Focus Areas
- conftest.py[123-131]

### Implementation notes
- Replace the string composition with `tempfile.mkdtemp(prefix="pytest-")` (optionally under `tempfile.gettempdir()`), and assign that returned path to `config.option.basetemp`.
- If you want deterministic cleanup, pair this with an ownership flag so the suite deletes only directories it created.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Docs suggest fixed basetemp 🐞 Bug ⚙ Maintainability
Description
Documentation still shows --basetemp=/tmp/pytest, which reintroduces the cross-session conflict
this PR is fixing and no longer matches pytest.ini. Users following docs will likely bring the
original race back.
Code

pytest.ini[11]

-  --basetemp=/tmp/pytest
Evidence
pytest.ini removed the fixed basetemp option, but docs still present it as a default/addopt and
explain it as a fixed temp root. That guidance conflicts with the new design and will cause users to
recreate the shared directory problem.

pytest.ini[4-14]
docs/pytest-options-and-markers.md[21-59]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Docs still instruct `--basetemp=/tmp/pytest`, which undermines this PR’s fix and is inconsistent with `pytest.ini`.
### Issue Context
This PR removed the ini-level fixed basetemp and introduced per-session basetemp via `pytest_configure`.
### Fix Focus Areas
- docs/pytest-options-and-markers.md[21-59]
- (Optionally) other docs pages that embed the same `pytest.ini` snippet
### Implementation notes
- Remove or update `--basetemp=/tmp/pytest` in documentation snippets.
- Replace the explanation bullet to describe the new behavior (unique per session), and document how to override `--basetemp` safely if needed.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. Short basetemp suffix 🐞 Bug ⛯ Reliability
Description
The generated basetemp uses only 8 hex characters of UUID (32 bits), which can collide under high
fan-out CI and reintroduce cross-session deletion conflicts. Using the full UUID (or more entropy)
eliminates this avoidable risk.
Code

conftest.py[130]

+        config.option.basetemp = f"/tmp/pytest-{uuid.uuid4().hex[:8]}"
Evidence
The code explicitly truncates uuid4().hex to 8 characters, limiting the namespace to 2^32
possibilities. Collisions are low probability but directly map back to the same failure mode (shared
basetemp and teardown deleting another run’s temp files).

conftest.py[129-130]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Basetemp uniqueness is limited by truncating UUID to 8 hex chars.
### Issue Context
This PR’s purpose is to avoid shared basetemp across sessions; collisions (even rare) are the same class of failure.
### Fix Focus Areas
- conftest.py[129-130]
### Implementation notes
- Use `uuid.uuid4().hex` without truncation, or include PID/time to increase entropy.
- Keep the directory name reasonably sized; full UUID is still short enough for paths.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider Grey Divider
Results up to commit 1ec9da9


🐞 Bugs (4) 📘 Rule violations (0) 📎 Requirement gaps (0) 📐 Spec deviations (0)

Grey Divider
Action required
1. Hardcoded /tmp basetemp 🐞 Bug ⛯ Reliability
Description
pytest_configure sets config.option.basetemp to a /tmp/... path, which is not portable and
will fail on native Windows runs. This also ignores the existing repo pattern of using
tempfile.gettempdir() for temp locations.
Code

conftest.py[R123-130]

+def pytest_configure(config: pytest.Config) -> None:
+    """Set a unique basetemp directory per session to prevent cross-session conflicts.
+
+    Args:
+        config (pytest.Config): Pytest configuration object used to set basetemp.
+    """
+    if config.option.basetemp is None:
+        config.option.basetemp = f"/tmp/pytest-{uuid.uuid4().hex[:8]}"
Evidence
The new hook hardcodes /tmp for basetemp. The project explicitly documents Windows usage, and the
same conftest already uses tempfile.gettempdir() for a shared temp directory, indicating temp root
should be platform-derived rather than hardcoded.

conftest.py[123-131]
README.md[12-18]
conftest.py[561-568]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`pytest_configure` hardcodes `/tmp/...` for `basetemp`, which breaks native Windows and is inconsistent with existing `tempfile.gettempdir()` usage.

### Issue Context
The repo documentation mentions Windows users. Other temp paths (e.g., virtctl cache dir) are derived from `tempfile.gettempdir()`.

### Fix Focus Areas
- conftest.py[123-131]

### Implementation notes
- Replace `"/tmp/..."` with something like:
 - `base = Path(tempfile.gettempdir())`
 - `config.option.basetemp = str(base / f"pytest-{uuid.uuid4().hex}")`
- Keep behavior of only setting when `config.option.basetemp is None`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Unconditional basetemp rmtree 🐞 Bug ⛨ Security
Description
Session teardown unconditionally deletes session.config.option.basetemp, so any user-provided
--basetemp (or an unexpectedly broad value) will be removed at the end of the run. This is a
data-loss footgun and is now more likely because this PR intentionally manipulates basetemp at
runtime.
Code

conftest.py[R129-130]

+    if config.option.basetemp is None:
+        config.option.basetemp = f"/tmp/pytest-{uuid.uuid4().hex[:8]}"
Evidence
The new code only sets basetemp when it is None, meaning a user-supplied --basetemp will
persist. The sessionfinish hook then always calls shutil.rmtree() on that value, which can delete
arbitrary directories if misconfigured or if a user set --basetemp for debugging/persistence.

conftest.py[123-131]
conftest.py[233-260]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`pytest_sessionfinish` always deletes `session.config.option.basetemp`. With the new `pytest_configure` behavior (only setting basetemp when None), a user-provided `--basetemp` can be deleted, creating a data-loss risk.

### Issue Context
The PR’s goal is cross-session isolation, but cleanup must not remove arbitrary user-selected paths.

### Fix Focus Areas
- conftest.py[123-131]
- conftest.py[233-260]

### Implementation notes
- Track whether basetemp was auto-generated, e.g.:
 - in `pytest_configure`, when you set `config.option.basetemp`, also set `config._mtv_generated_basetemp = True`.
 - if basetemp is already set, set the flag to False.
- In `pytest_sessionfinish`, only `rmtree()` when the flag is True.
- Additionally, defensively validate the path before deleting:
 - ensure it is inside `tempfile.gettempdir()` (resolve/realpath check)
 - ensure it matches your expected prefix (e.g., `pytest-`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
3. Docs suggest fixed basetemp 🐞 Bug ⚙ Maintainability
Description
Documentation still shows --basetemp=/tmp/pytest, which reintroduces the cross-session conflict
this PR is fixing and no longer matches pytest.ini. Users following docs will likely bring the
original race back.
Code

pytest.ini[11]

-  --basetemp=/tmp/pytest
Evidence
pytest.ini removed the fixed basetemp option, but docs still present it as a default/addopt and
explain it as a fixed temp root. That guidance conflicts with the new design and will cause users to
recreate the shared directory problem.

pytest.ini[4-14]
docs/pytest-options-and-markers.md[21-59]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
Docs still instruct `--basetemp=/tmp/pytest`, which undermines this PR’s fix and is inconsistent with `pytest.ini`.

### Issue Context
This PR removed the ini-level fixed basetemp and introduced per-session basetemp via `pytest_configure`.

### Fix Focus Areas
- docs/pytest-options-and-markers.md[21-59]
- (Optionally) other docs pages that embed the same `pytest.ini` snippet

### Implementation notes
- Remove or update `--basetemp=/tmp/pytest` in documentation snippets.
- Replace the explanation bullet to describe the new behavior (unique per session), and document how to override `--basetemp` safely if needed.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Short basetemp suffix 🐞 Bug ⛯ Reliability
Description
The generated basetemp uses only 8 hex characters of UUID (32 bits), which can collide under high
fan-out CI and reintroduce cross-session deletion conflicts. Using the full UUID (or more entropy)
eliminates this avoidable risk.
Code

conftest.py[130]

+        config.option.basetemp = f"/tmp/pytest-{uuid.uuid4().hex[:8]}"
Evidence
The code explicitly truncates uuid4().hex to 8 characters, limiting the namespace to 2^32
possibilities. Collisions are low probability but directly map back to the same failure mode (shared
basetemp and teardown deleting another run’s temp files).

conftest.py[129-130]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
Basetemp uniqueness is limited by truncating UUID to 8 hex chars.

### Issue Context
This PR’s purpose is to avoid shared basetemp across sessions; collisions (even rare) are the same class of failure.

### Fix Focus Areas
- conftest.py[129-130]

### Implementation notes
- Use `uuid.uuid4().hex` without truncation, or include PID/time to increase entropy.
- Keep the directory name reasonably sized; full UUID is still short enough for paths.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider Grey Divider
Qodo Logo

@redhat-qe-bot2

Copy link
Copy Markdown

Report bugs in Issues

Welcome! 🎉

This pull request will be automatically processed with the following features:

🔄 Automatic Actions

  • Reviewer Assignment: Reviewers are automatically assigned based on the OWNERS file in the repository root
  • Size Labeling: PR size labels (XS, S, M, L, XL, XXL) are automatically applied based on changes
  • Issue Creation: Disabled for this repository
  • Branch Labeling: Branch-specific labels are applied to track the target branch
  • Auto-verification: Auto-verified users have their PRs automatically marked as verified
  • Labels: All label categories are enabled (default configuration)

📋 Available Commands

PR Status Management

  • /wip - Mark PR as work in progress (adds WIP: prefix to title)
  • /wip cancel - Remove work in progress status
  • /hold - Block PR merging (approvers only)
  • /hold cancel - Unblock PR merging
  • /verified - Mark PR as verified
  • /verified cancel - Remove verification status
  • /reprocess - Trigger complete PR workflow reprocessing (useful if webhook failed or configuration changed)
  • /regenerate-welcome - Regenerate this welcome message

Review & Approval

  • /lgtm - Approve changes (looks good to me)
  • /approve - Approve PR (approvers only)
  • /automerge - Enable automatic merging when all requirements are met (maintainers and approvers only)
  • /assign-reviewers - Assign reviewers based on OWNERS file
  • /assign-reviewer @username - Assign specific reviewer
  • /check-can-merge - Check if PR meets merge requirements

Testing & Validation

  • /retest tox - Run Python test suite with tox
  • /retest build-container - Rebuild and test container image
  • /retest conventional-title - Validate commit message format
  • /retest all - Run all available tests

Container Operations

  • /build-and-push-container - Build and push container image (tagged with PR number)
    • Supports additional build arguments: /build-and-push-container --build-arg KEY=value

Cherry-pick Operations

  • /cherry-pick <branch> - Schedule cherry-pick to target branch when PR is merged
    • Multiple branches: /cherry-pick branch1 branch2 branch3

Label Management

  • /<label-name> - Add a label to the PR
  • /<label-name> cancel - Remove a label from the PR

✅ Merge Requirements

This PR will be automatically approved when the following conditions are met:

  1. Approval: /approve from at least one approver
  2. Status Checks: All required status checks must pass
  3. No Blockers: No wip, hold, has-conflicts labels and PR must be mergeable (no conflicts)
  4. Verified: PR must be marked as verified

📊 Review Process

Approvers and Reviewers

Approvers:

  • myakove
  • solenoci

Reviewers:

  • krcmarik
  • myakove
  • solenoci
Available Labels
  • hold
  • verified
  • wip
  • lgtm
  • approve
  • automerge
AI Features
  • Conventional Title: Mode: fix (claude/claude-opus-4-6[1m])
  • Cherry-Pick Conflict Resolution: Enabled (claude/claude-opus-4-6[1m])

💡 Tips

  • WIP Status: Use /wip when your PR is not ready for review
  • Verification: The verified label is automatically removed on each new commit
  • Cherry-picking: Cherry-pick labels are processed when the PR is merged
  • Container Builds: Container images are automatically tagged with the PR number
  • Permission Levels: Some commands require approver permissions
  • Auto-verified Users: Certain users have automatic verification and merge privileges

For more information, please refer to the project documentation or contact the maintainers.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Mar 25, 2026
Comment thread conftest.py Resolved
Comment thread conftest.py Resolved
… conflicts

The fixed --basetemp=/tmp/pytest was shared across all test sessions. When
multiple sessions ran in parallel, one session's teardown (shutil.rmtree)
could delete another session's temp files (e.g., SSL cert files).

Each session now gets a unique basetemp via pytest_configure hook.
Replace hardcoded /tmp/ with tempfile.gettempdir() for platform
consistency. Remove outdated --basetemp=/tmp/pytest from documentation
snippets to match the current pytest.ini configuration.
@qodo-code-review

qodo-code-review Bot commented Mar 25, 2026 •

Copy link
Copy Markdown

Persistent review updated to latest commit 3920879

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/pytest-options-and-markers.md`:
- Line 56: The HTML output still contains the old hardcoded
--basetemp=/tmp/pytest entry; regenerate the corresponding
troubleshooting-and-diagnostics.html from the updated
pytest-options-and-markers.md so the HTML reflects the new auto-generated
basetemp behavior (mentioning the session-specific path and the override via
--basetemp=/path), then commit the regenerated HTML to the repo to keep docs
consistent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6d8dcb93-94d0-4492-bb01-3cf3df23d12a

📥 Commits

Reviewing files that changed from the base of the PR and between 1ec9da9 and 3920879.

📒 Files selected for processing (12)
  • conftest.py
  • docs/automation-and-release.md
  • docs/container-and-openshift-job-execution.md
  • docs/development-workflow.md
  • docs/introduction.md
  • docs/optional-integrations-and-secrets.md
  • docs/project-structure.md
  • docs/pytest-options-and-markers.md
  • docs/quickstart-first-run.md
  • docs/runtime-configuration.md
  • docs/troubleshooting-and-diagnostics.md
  • pytest.ini
💤 Files with no reviewable changes (10)
  • pytest.ini
  • docs/introduction.md
  • docs/optional-integrations-and-secrets.md
  • docs/project-structure.md
  • docs/container-and-openshift-job-execution.md
  • docs/automation-and-release.md
  • docs/quickstart-first-run.md
  • docs/troubleshooting-and-diagnostics.md
  • docs/runtime-configuration.md
  • docs/development-workflow.md

Comment thread docs/pytest-options-and-markers.md Resolved
@qodo-code-review

qodo-code-review Bot commented Mar 25, 2026 •

Copy link
Copy Markdown

Persistent review updated to latest commit 3920879

@krcmarik

Copy link
Copy Markdown
Collaborator Author

/verified
/cherry-pick v2.11 v2.10

@redhat-qe-bot

Copy link
Copy Markdown

Cherry-pick requested for PR: fix: make pytest basetemp unique per session to prevent cross-session conflicts by user krcmarik
Adding label/s cherry-pick-v2.11 cherry-pick-v2.10 for automatic cherry-pick once the PR is merged

@myakove

myakove commented Mar 25, 2026

Copy link
Copy Markdown
Collaborator

/lgtm
/approve

@myakove
myakove enabled auto-merge (squash) March 25, 2026 09:04
@myakove
myakove merged commit 7c19d19 into RedHatQE:main Mar 25, 2026
7 checks passed
redhat-qe-bot2 pushed a commit that referenced this pull request Mar 25, 2026
… conflicts (#387)

* fix: make pytest basetemp unique per session to prevent cross-session conflicts

The fixed --basetemp=/tmp/pytest was shared across all test sessions. When
multiple sessions ran in parallel, one session's teardown (shutil.rmtree)
could delete another session's temp files (e.g., SSL cert files).

Each session now gets a unique basetemp via pytest_configure hook.

* fix: use tempfile.gettempdir() for basetemp and update docs

Replace hardcoded /tmp/ with tempfile.gettempdir() for platform
consistency. Remove outdated --basetemp=/tmp/pytest from documentation
snippets to match the current pytest.ini configuration.
@redhat-qe-bot2

Copy link
Copy Markdown

Cherry-pick conflicts were resolved by AI

Cherry-picked PR fix: make pytest basetemp unique per session to prevent cross-session conflicts into v2.11: #389
Conflicts were automatically resolved by AI (claude/claude-opus-4-6[1m]).

Manual verification is required — please review the changes and test before merging.

redhat-qe-bot2 pushed a commit that referenced this pull request Mar 25, 2026
… conflicts (#387)

* fix: make pytest basetemp unique per session to prevent cross-session conflicts

The fixed --basetemp=/tmp/pytest was shared across all test sessions. When
multiple sessions ran in parallel, one session's teardown (shutil.rmtree)
could delete another session's temp files (e.g., SSL cert files).

Each session now gets a unique basetemp via pytest_configure hook.

* fix: use tempfile.gettempdir() for basetemp and update docs

Replace hardcoded /tmp/ with tempfile.gettempdir() for platform
consistency. Remove outdated --basetemp=/tmp/pytest from documentation
snippets to match the current pytest.ini configuration.
@redhat-qe-bot2

Copy link
Copy Markdown

Cherry-pick conflicts were resolved by AI

Cherry-picked PR fix: make pytest basetemp unique per session to prevent cross-session conflicts into v2.10: #390
Conflicts were automatically resolved by AI (claude/claude-opus-4-6[1m]).

Manual verification is required — please review the changes and test before merging.

@redhat-qe-bot2

Copy link
Copy Markdown

New container for ghcr.io/redhatqe/mtv-api-tests:latest published

rgolangh pushed a commit to rgolangh/mtv-api-tests-1 that referenced this pull request Mar 25, 2026
… conflicts (RedHatQE#387)

* fix: make pytest basetemp unique per session to prevent cross-session conflicts

The fixed --basetemp=/tmp/pytest was shared across all test sessions. When
multiple sessions ran in parallel, one session's teardown (shutil.rmtree)
could delete another session's temp files (e.g., SSL cert files).

Each session now gets a unique basetemp via pytest_configure hook.

* fix: use tempfile.gettempdir() for basetemp and update docs

Replace hardcoded /tmp/ with tempfile.gettempdir() for platform
consistency. Remove outdated --basetemp=/tmp/pytest from documentation
snippets to match the current pytest.ini configuration.
@krcmarik
krcmarik deleted the basetemp branch September 15, 2026 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants