pytest

specifing '-c path/pytest.ini' in pytest.main() only uses function pattern(python_functions) for one file

specifing '-c path/pytest.ini' in pytest.main() only uses function pattern(python_functions) for one file Question: I what to call pytest.main this way: pytest.main([‘-c’.’pathpytest.ini’, ‘teststestfile1::src_func1′,’teststestfile2::src_func2’]) so basically I want to have the pytest.ini test outside the tests folder and call a list of tests from different files on the tests folder. I have defined a pattern for the …

Total answers: 1

pytest finding and not finding modules to test

pytest finding and not finding modules to test Question: I was going to post this question in code review because rather than a solution I wanted for python experts to check my code. But while preparing the code I found some related issue so I finally decided to ask it here since it is not …

Total answers: 3

Can PyTest addoption be made global variables across all files?

Can PyTest addoption be made global variables across all files? Question: I am trying to make user input from pytest addoption to be accessible through all files I have a conftest.py file with code import pytest def pytest_addoption(parser): try: parser.addoption(‘–user’, action=’store’, default=”, help=’Login Email for the API tests’) parser.addoption(‘–pwd’, action=’store’, default=”, help=’Login Password for the …

Total answers: 2

How to avoid showing orginal exception in pytest when reraising exception?

How to avoid showing orginal exception in pytest when reraising exception? Question: I use a library with very deep stack. When there is an exception, trace is enormous (~6 pages), even the true reason is a side effect (no permission), and it’s very clear from exception text. It is really confusing in tests, so I …

Total answers: 1

Test code and branch coverage simultanously with Pytest

Test code and branch coverage simultanously with Pytest Question: I am using pytest to test my Python code. To test for code coverage (C0 coverage) I run pytest –cov and I can specify my desired coverage in my pyproject.toml file like this: [tool.coverage.report] fail_under = 95 I get this result with a coverage a 96.30%: …

Total answers: 1

Expect value of a dropdown select based on option text

Expect value of a dropdown select based on option text Question: We have a dropdown select <select id="favorite-colors" multiple> <option value="R">Red</option> <option value="G">Green</option> <option value="B">Blue</option> </select> In playwright we can use to check the value expect(locator).to_have_values([re.compile(r"R"), re.compile(r"G")]) See: https://playwright.dev/python/docs/api/class-locatorassertions#locator-assertions-to-have-values But how can I use the expect to check if the selection is "Red" or "Green" …

Total answers: 2

Pytest test fails for all cases when only one fails

Pytest test fails for all cases when only one fails Question: I have a Pytest file structured as below: @pytest.fixture(scope="class") def driver_init(request): driver = webdriver.Chrome("path tp driver") driver.maximize_window() request.cls.driver = driver driver.get(url) # code that navigates to a page that I need to validate data on yield driver.close() pytest.mark.usefixtures("driver_init") @pytest.mark.parametrize("user", get_users()) class TestValidate: @pytest.mark.order(1) def …

Total answers: 1