Skip to content

pytest.config has removed, but how can I push cmdline value to testclass #7137

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
wdq347 opened this issue Apr 30, 2020 · 2 comments
Closed

Comments

@wdq347
Copy link

wdq347 commented Apr 30, 2020

problem

when upgrade to 5.0 version, pytest.config has removed, I canot push cmdline value to testclass

My test arch only uses one testclass with only one testcase which is extended by parametrize testcase yml file, but I want use cmdline value for testcase yml file.

my code is following

conftest.py file

import pytest
def pytest_addoption(parser):
    parser.addoption("--bed", action="store", default="__testbed.yml",
                     help="testbed file")

testxx.py file

class TestTotal():
    bed_file = pytest.config.getoption("--bed")
    casedir = bed.casedir

    @pytest.mark.parametrize("serial, desc, ops, expect, resetops, judgetype", yml_read.ptest_read_yml(casedir, template))
    def test_cases(self, serial, desc, ops, expect, resetops, judgetype):
        .........................................

trying

I try request.config, buf failed for bed will be used before testcase and fixture is useless

I try pytest_generate_tests to set cls var bed_file, also failed for cls var cannot be seen in TestTotal and only be seen in test function

I only hope varaibles to hold cmdline argument

who can help me, thanks very much!

@jstoja
Copy link

jstoja commented Apr 30, 2020

Hello @wdq347,

pytest.config was deprecated in version 4 and has been removed in version 5.
You can use pytest.request to achieve the similar (same) result.

If you need more information about why it was deprecated and examples with pytest.request, please look at the original issue #3050 .

If you don't have any other question, you can close this ticket :)

@wdq347
Copy link
Author

wdq347 commented May 7, 2020

Thanks @jstoja

using pytest_generate_tests and metafunc.parametrize will solve this probelm

conftest.py file

import os
import pytest
import yml_read

def pytest_addoption(parser):
    parser.addoption("--bed", action="store", default="__testbed.yml",
                     help="testbed file")

def pytest_generate_tests(metafunc):
    bed_file = metafunc.config.getoption("--bed")
...................
    metafunc.parametrize("serial, desc, ops, expect, resetops, judgetype", yml_read.ptest_read_yml(bed_file))

@wdq347 wdq347 closed this as completed May 7, 2020
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