testing

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

What to tests in ci run vs pytest, and why

What to tests in ci run vs pytest, and why Question: I have a python repo in github. If I understood it correctly there are mainly two ways in which tests can be automated: using run in a ci.yml file using test_… files under a folder called test (at root level) and then execute them …

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

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

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

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

Different output in leetcode and visual studio code for python (4. Median)

Different output in leetcode and visual studio code for python (4. Median) Question: Recently I’ve just taken an interest in learning python, however, this one has really defeated me. The specific question on Leetcode is "4. Median of Two Sorted Arrays": Given two sorted arrays nums1 and nums2 of size m and n respectively, return …

Total answers: 1

Abstract class and abastract Unitest

Abstract class and abastract Unitest Question: I use Django Rest Framework and I wrote something like this: class Vehicule(ABC): wheel = None roof = None def drive(): use wheel and roof, blabla… class Car(Vehicule): wheel = 4 roof = True class Bike(Vehicule): wheel = 2 roof = False It’s working good and I want to …

Total answers: 2

pytest mark parametrize a fixture

pytest mark parametrize a fixture Question: I want to test a function get_xyz(a, b, foo), where foo is a class. A foo_fixture is defined in a conftest.py like so: @pytest.fixture() def foo_fixture(): return Foo() The fixture simply returns a new instance of a class Foo. How would I parametrize this foo_fixture as an argument to …

Total answers: 1

Integration testing FastAPI with user authentication

Integration testing FastAPI with user authentication Question: I am trying to write some integration tests for my FastAPI endpoints and am not sure what the best solution is to testing the endpoints that require a user to be logged in. I am following the FastAPI authentication documentation for my auth flow which is just username …

Total answers: 1