Skip to content
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

Cassette file paths break if test parameters include relative path-like characters #38

Open
shevron opened this issue Jun 10, 2020 · 0 comments

Comments

@shevron
Copy link

shevron commented Jun 10, 2020

I am running a test that uses pytest-vcr and also has @pytest.mark.parametrize where parameters are path-segment like strings, sometimes containing relative (e.g. /../) or absolute (e.g /foo) path segments.

This causes the cassette file locations to be created all over the place, and sometimes even cause overwrite attempts of two different values point to the real file system location of a cassette file.

For example the following test:

import pytest
import requests


@pytest.mark.vcr()
@pytest.mark.parametrize('path', [
    'foo/bar',
    '/foo/bar',
    'foo/../bar',
    'foo/../../bar',
    '/../foo/bar',
    '../foo/bar',
])
def test_with_some_paths(path):
    r = requests.get('http://example.com/?q={}'.format(path))
    assert r

Assuming saved in tests/test_vcr.py, will cause .yaml files to be created all over the place. I've added spaces around directory separator to designate that these are real directories created on my file system, not literal forward-slashes which is a parts of the file / directory name:

tests / test_vcr.py
tests / bar].yaml
tests / cassettes / foo / bar].yaml
tests / cassettes / test_with_some_paths[ / foo / bar].yaml
tests / cassettes / test_with_some_paths[.. / foo / bar].yaml
tests / cassettes / test_with_some_paths[foo / bar].yaml
tests / cassettes / bar].yaml

It seems to me that some normalization and sanitization is in order when dealing with parameterized tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant