You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a test depends on extra shared cassettes, we cannot override the default vcr_cassette_dir through cassette_library_dir key returned from vcr_config fixture.
While vcr_cassette_dir is correctly used to set where the current cassette is read/written, it's ignored when searching for extra cassettes.
To Reproduce
A simplified Minimal (Not Working) Example would be:
# file: test_eof.py@pytest.fixture(scope="module")defvcr_config(baseline_dir):
# baseline_dir being another fixture set elsewhereassertos.path.exists(baseline_dir)
return {
"cassette_library_dir" : os.path.join(baseline_dir, 'cassettes/test_eof'),
# I guess I should be able to use module.purebasename instead of hardcoding "test_eof"
}
@pytest.mark.vcr("cop_access_token.yaml")deftest_sometest():
CodethatexecutesarequestthatIexpectrecordedin:
-> ${BASELINE_DIR}/cassettes/test_eof/cop_access_token.yamlButthecassettessearchedare:
- $(current_test_dir)/cassettes/test_eof/cop_access_token.yaml<--notthepathexpected-and ${BASELINE_DIR}/cassettes/test_eof/test_sometest.yaml<-thecurrenttest
Expected behavior
The shared cassettes should be searched in vcr_config()["cassette_library_dir"]
Possible patch
Adding the following instruction in _vcr.use_cassette() seems enough to fix the issue.
# just after >> merged_config = merge_kwargs(config, markers) <<vcr_cassette_dir=config.get('cassette_library_dir', vcr_cassette_dir) # <<-- The proposed fix
Or maybe, it's vcr_cassette_dir fixture itself that needs the patching? I don't know what's better.
@pytest.fixture(scope="module") # type: ignore
def vcr_cassette_dir(request: SubRequest) -> str:
"""Each test module has its own cassettes directory to avoid name collisions.
For example each test module could have test function with the same names:
- test_users.py:test_create
- test_profiles.py:test_create
"""
+ config = request.getfixturevalue("vcr_config")+ if "cassette_library_dir" in config:+ return config["cassette_library_dir"]
module = request.node.fspath # current test file
return os.path.join(module.dirname, "cassettes", module.purebasename)
Environment:
OS: ubuntu
Python version: 3.11
pytest-recording version: 0.13.2
pytest version: 8.0.2
The text was updated successfully, but these errors were encountered:
Describe the bug
When a test depends on extra shared cassettes, we cannot override the default
vcr_cassette_dir
throughcassette_library_dir
key returned fromvcr_config
fixture.While
vcr_cassette_dir
is correctly used to set where the current cassette is read/written, it's ignored when searching for extra cassettes.To Reproduce
A simplified Minimal (Not Working) Example would be:
Expected behavior
The shared cassettes should be searched in
vcr_config()["cassette_library_dir"]
Possible patch
Adding the following instruction in
_vcr.use_cassette()
seems enough to fix the issue.Or maybe, it's
vcr_cassette_dir
fixture itself that needs the patching? I don't know what's better.Environment:
The text was updated successfully, but these errors were encountered: