Skip to content

Conversation

dholth
Copy link
Contributor

@dholth dholth commented Jul 15, 2025

Description

A different strategy might be to copy this entire folder to a temporary path as a session scoped fixture.

Fix #15011

Checklist - did you ...

  • Add a file to the news directory (using the template) for the next release's release notes?
  • Add / update necessary tests?
  • Add / update outdated documentation?

@dholth dholth requested a review from a team as a code owner July 15, 2025 21:26
@github-project-automation github-project-automation bot moved this to 🆕 New in 🔎 Review Jul 15, 2025
@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label Jul 15, 2025
Copy link

codspeed-hq bot commented Jul 15, 2025

CodSpeed Instrumentation Performance Report

Merging #15013 will not alter performance

Comparing 15011-test-suite-modifies-src (15bf148) with main (89862dd)

Summary

✅ 21 untouched benchmarks

@kenodegard
Copy link
Contributor

kenodegard commented Jul 15, 2025

What if we refactor support_file into fixtures instead that handles the copying for us?

SUPPORT_DIR = Path(__file__).parent / "env" / "support"


@pytest.fixture
def support_file_url(support_file_server_port: int) -> Callable[[str], str]:
    def support_file_url(path: str) -> str:
        return f"http://127.0.0.1:{support_file_server_port}/{filename}"

    return support_file_url


@pytest.fixture
def support_file(path_factory: PathFactoryFixture) -> Callable[[str], Path]:
    def support_file(path: str) -> Path:
        src = SUPPORT_DIR / path
        dst = path_factory()
        shutil.copytree(src, dst)
        return dst

    return support_file

@dholth
Copy link
Contributor Author

dholth commented Jul 16, 2025

What if we refactor support_file into fixtures instead that handles the copying for us?

SUPPORT_DIR = Path(__file__).parent / "env" / "support"


@pytest.fixture
def support_file_url(support_file_server_port: int) -> Callable[[str], str]:
    def support_file_url(path: str) -> str:
        return f"http://127.0.0.1:{support_file_server_port}/{filename}"

    return support_file_url


@pytest.fixture
def support_file(path_factory: PathFactoryFixture) -> Callable[[str], Path]:
    def support_file(path: str) -> Path:
        src = SUPPORT_DIR / path
        dst = path_factory()
        shutil.copytree(src, dst)
        return dst

    return support_file

Added

@dholth dholth enabled auto-merge (squash) July 16, 2025 14:20
"""
source = Path(__file__).parents[0] / "env" / "support"
base = tmp_path / "support"
if not base.exists(): # tmp_path is session scoped
Copy link
Contributor

Choose a reason for hiding this comment

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

tmp_path is function scoped, so this will be copied every time this fixture is used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It crashes without the "if not base.exists()" check because the destination file is already there.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since we don't specify the scope it defaults to the function scope. Also, if we set the scope to session:

@pytest.fixture(scope="session")
def support_file_isolated(tmp_path):
    ...

tmp_path will error:

Screenshot 2025-07-16 at 14 42 04

Copy link
Contributor Author

@dholth dholth Jul 16, 2025

Choose a reason for hiding this comment

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

Works fine for me, with no explicit scope. Fixture is used only twice in methods that were both named "test_create_advanced_pip" before this PR. It does seem like the same fixture receives the same tmp_path both times it's instantiated for the tests, which is acceptable here.

% pytest -k advanced_pip
====================================================================== test session starts ======================================================================
platform darwin -- Python 3.12.2, pytest-8.3.4, pluggy-1.5.0 -- /Users/dholth/prog/conda/devenv/Darwin/arm64/envs/devenv-3.12-c/bin/python
cachedir: .pytest_cache
conda.__file__: /Users/dholth/prog/conda/conda/__init__.py
rootdir: /Users/dholth/prog/conda
configfile: pyproject.toml
testpaths: tests
plugins: cov-6.0.0, timeout-2.2.0, rerunfailures-12.0, xdoctest-1.2.0, xprocess-1.0.2, mock-3.14.0, split-0.10.0
collected 2395 items / 2393 deselected / 2 selected                                                                                                             

tests/env/test_create.py::test_create_advanced_pip PASSED                                                                                                 [ 50%]
tests/env/test_env.py::test_env_advanced_pip PASSED          

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kenodegard if you need a specific change to merge this PR, please make it directly in the branch.

@dholth dholth requested a review from kenodegard July 16, 2025 19:00
@dholth dholth moved this from 🆕 New to 👀 In Review in 🔎 Review Jul 17, 2025
@dholth dholth requested a review from travishathaway July 28, 2025 13:55
@dholth dholth merged commit 560fea3 into main Jul 30, 2025
75 checks passed
@dholth dholth deleted the 15011-test-suite-modifies-src branch July 30, 2025 16:38
@github-project-automation github-project-automation bot moved this from 👀 In Review to 🏁 Done in 🔎 Review Jul 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed [bot] added once the contributor has signed the CLA
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Test suite modifies tests/env/support
4 participants