-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Avoid modifying tests/env/support/ during test run #15013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
CodSpeed Instrumentation Performance ReportMerging #15013 will not alter performanceComparing Summary
|
What if we refactor 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 |
""" | ||
source = Path(__file__).parents[0] / "env" / "support" | ||
base = tmp_path / "support" | ||
if not base.exists(): # tmp_path is session scoped |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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 ...
news
directory (using the template) for the next release's release notes?