pytest

Pytest mocker failing to find Path

Pytest mocker failing to find Path Question: I am working with someone else’s testing code, and they make extensive use of mocker. The problem is that I changed the underlying code so it tests for the existence of a file using Path ().is_file. Now I need to mock Path ().is_file so it returns True. I …

Total answers: 1

Pytest missing 1 required positional argument with fixture

Pytest missing 1 required positional argument with fixture Question: I’m using vscode as IDE I have code a very simple usage of pytest fixture but it doesn’t working when basic example fixture found in the pytest documentation are working well : @pytest.fixture def declare_hexidict(): hd = hexidict() rvc = ReferenceValueCluster() rv = ReferenceValue(init=3) hd_var = …

Total answers: 2

In pytest, is there a way to mock an already imported variable without having to patch for every single test?

In pytest, is there a way to mock an already imported variable without having to patch for every single test? Question: So to be specific, we’re using SqlAlchemy and session, and we use define it only once at say, at utils/sessions.py. like following : #utils/sessions.py from sqlalchemy.orm import scoped_session, sessionmaker session = scoped_session (sessionmaker( …. …

Total answers: 2

No tests were found / collected 0 items / empty suite

No tests were found / collected 0 items / empty suite Question: Currently learning Python to automate API and faced the first significant issue I found no solution for. When I try to run my test either with Run or with terminal by python -m pytest or just pytest/py.test commands, I get this in the …

Total answers: 1

Problem in using conftest.py from a packaged pytest framework

Problem in using conftest.py from a packaged pytest framework Question: I am working on a pytest-framework that will be packed as a package. The setup file i am using for this is as this: setup( name=’MyTestFrameWork’, version="2", author=’my name’, author_email=’[email protected]’, description=’My test framework’, long_description=open(‘README.md’, ‘rb’).read().decode(‘utf-8′), url=’http://my.test.framework.dk’, license="Free loot", packages=find_namespace_packages(), python_requires=">=3.10", include_package_data=True, install_requires=[‘pytest’], entry_points={"pytest11": ["MyTestFrameWork = …

Total answers: 1

Pytest retry logic upon one unsuccessful test

Pytest retry logic upon one unsuccessful test Question: In my pytest suite, I run plenty of iOS UI tests. Which comes with plenty of frustrating issues. Im experimenting with the use of a hook based retry logic. Essentially, I have a pytest_runtest_call hook, where I collect the output of a test via a yield, and …

Total answers: 1

FastAPI + pytest unable to clean Django ORM

FastAPI + pytest unable to clean Django ORM Question: I’m creating a FastAPI project that integrates with the Django ORM. When running pytest though, the PostgreSQL database is not rolling back the transactions. Switching to SQLite, the SQLite database is not clearing the transactions, but it is tearing down the db (probably because SQLite uses …

Total answers: 1

ScopeMismatch when i try to make setup_teardown pytest function

ScopeMismatch when i try to make setup_teardown pytest function Question: My goal is to create a fixture that will run once at the beginning of the class function test and initialize the attributes I need in self. To do this, I created a fixture with the scope of the class and applied it directly to …

Total answers: 1

Pytests doesn't find a test if explicitely named

Pytests doesn't find a test if explicitely named Question: Have the following project tree (just a tutorial to learn pytest): (pytest) bob@Roberts-Mac-mini ds % tree . ├── ds │ └── __init__.py └── tests ├── __pycache__ │ ├── test_compare.cpython-311-pytest-7.2.0.pyc │ ├── test_square.cpython-311-pytest-7.2.0.pyc │ └── test_stack.cpython-311-pytest-7.2.0.pyc ├── test_compare.py └── test_square.py 4 directories, 6 files and from its …

Total answers: 1