pytest

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: './instance/test_db.sqlite'

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: './instance/test_db.sqlite' Question: I’m having a trouble with tear down of my pytest context. I have a Flask app which creates sqlite3 database in my instance directory, looks like this: # ./src/app_factory/__init__.py def create_app(): app = Flask(__name__, instance_path=f'{os.path.abspath("instance")}’, instance_relative_config=True, …

Total answers: 1

pytest, xdist, and sharing generated file dependencies

pytest, xdist, and sharing generated file dependencies Question: I have multiple tests that need require an expensive-to-generate file. I’d like the file to be re-generated on every test run, but no more than once. To complicate the matter, both these tests as well as the file depend on an input parameter. def expensive(param) -> Path: …

Total answers: 1

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