pytest

Can I skip a test (or mark it as inconclusive) in pytest while it is running?

Can I skip a test (or mark it as inconclusive) in pytest while it is running? Question: I am aware of pytest‘s decorators to mark tests as to be skipped (conditionally). However, all those are evaluated before the test starts. I have a couple of tests that require a user interaction (those are not run …

Total answers: 2

Testing concurrent.futures.TimeoutError and logging in a threaded function using Pytest

Testing concurrent.futures.TimeoutError and logging in a threaded function using Pytest Question: I’ve come across a testing challenge in my Python project and I’m hoping to get some insights from the community. I have a utility module containing a function threaded_execute which utilizes the concurrent.futures module to execute a function in a separate thread. If a …

Total answers: 1

ImportError: cannot import name 'url_quote' from 'werkzeug.urls'

ImportError: cannot import name 'url_quote' from 'werkzeug.urls' Question: Environment: Python 3.10.11 Flask==2.2.2 I run my Flask backend code in docker container, with BASE Image: FROM pytorch/pytorch:2.0.1-cuda11.7-cudnn8-runtime But when I run the pytest with version pytest 7.4.2, pip install pytest pytest it raised an Error, with logs: ==================================== ERRORS ==================================== _____________ ERROR collecting tests/test_fiftyone_utils_utils.py ______________ ImportError …

Total answers: 6

Coverage report for 'pytest' different when run in code vs CLI

Coverage report for 'pytest' different when run in code vs CLI Question: When I use the pytest CLI to run some tests against my small module, the coverage report that is output is complete and shows 100% coverage. However, when I run the tests in code using the pytest module, the coverage report is incomplete …

Total answers: 1

How to make PyTest use the `conftest.py` of a parent directory

How to make PyTest use the `conftest.py` of a parent directory Question: I am working on a suite of tests for a project that were not written by me. The way they were set up is as follows root/ conftest.py testType1/ a.py testType2/ etc. The file a.py is as follows class TestClass: value_thats_important = None …

Total answers: 1

Selenium Python Element Click Intercepted

Selenium Python Element Click Intercepted Question: I’m trying to run a test in Selenium Webdriver Python, but I got an error saying as on the screenshot: this is the xpath for the register button: //button[@class=’tutor-btn tutor-btn-primary’] What I tried so far: setup.find_element("xpath", "//button[@class=’tutor-btn tutor-btn-primary’]").click() and setup.find_element("xpath", "//button[@type=’submit’ and (contains(@class,’tutor-btn tutor-btn-primary’)) and(contains(text(),’Register’))]").click() but none works, any …

Total answers: 4

Pytest AttributeError: 'TestMyTest' object has no attribute

Pytest AttributeError: 'TestMyTest' object has no attribute Question: I have multiple tests written in the following format. When the test is run, why do some tests fail with exception AttributeError: ‘TestMyTest’ object has no attribute ‘var1’? var1 is defined as class variable in test_init(). Still the exception is thrown in test_1(). @pytest.fixture(scope="module") def do_setup(run_apps): """ …

Total answers: 1

Mock a library method response using pytest

Mock a library method response using pytest Question: I am new to pytest, i want to create a test for a method called inside a library. So following is my sample usecase. I have a python library called core: Inside core there is a folder called p_core. Inside p_core there is python file common.py In …

Total answers: 1

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