Skip to content

mapping the fixture parameter with the test method parameter #1263

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

Closed
markshao opened this issue Dec 16, 2015 · 3 comments
Closed

mapping the fixture parameter with the test method parameter #1263

markshao opened this issue Dec 16, 2015 · 3 comments

Comments

@markshao
Copy link
Contributor

I have the test cases to test some sftp related features under different OS . For example test the file path existence under both windows and Linux.

The test function support two kind of parameters , first parameter is the fixture returns a paramiko ssh connection , the second parameter is a normal string parameter for the file path.

import pytest

@pytest.fixture(scope="module", params=("linux", "windows"))
def ssh_connection(request):
    pass


class TestSftpUtil(object):
    @pytest.mark.parametrize("path", [("c:/windows",), ("/root/path",)])
    def test_is_file(self, ssh_connection, path):
        assert True

Now the pytest traverse all the possible parameter groups

test/test_sftputil.py::TestSftpUtil::test_is_file[linux-path0] PASSED
test/test_sftputil.py::TestSftpUtil::test_is_file[linux-path1] PASSED
test/test_sftputil.py::TestSftpUtil::test_id_dir[linux] PASSED
test/test_sftputil.py::TestSftpUtil::test_is_file[windows-path0] PASSED
test/test_sftputil.py::TestSftpUtil::test_is_file[windows-path1] PASSED
test/test_sftputil.py::TestSftpUtil::test_id_dir[windows] PASSED

But some parameter group is unnecessary, like windows OS + linux file path . Is there a way to define the mapping between the normal parametrize with the fixture params (I don't want to write too much if ... else ... in the test method )

@RonnyPfannschmidt
Copy link
Member

is that a duplicate/variant of #681?

@markshao
Copy link
Contributor Author

Yes , I agree with that

@RonnyPfannschmidt
Copy link
Member

Thanks, Closing as duplicate of #681

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

2 participants