Category : pytest

I am having issues accessing endpoints in my flask app, which are protected by login when I run my tests using pytest. It seems like the cookies are not retained on the test client. conftest.py: @pytest.fixture def client(): ”’Client fixture”’ app = create_app({‘TESTING’: True}) with app.test_client() as client: yield client @pytest.fixture def create_user(): ”’Provide a ..

Read more

I have a class X in x.py from c import COBJ class X: # to be tested def f(self, a): x = COBJ.get(a) return x + ‘-AddedInX.f’ And c.py has class Singleton(type): _instances = {} def __call__(cls, *args, **kwargs): if cls not in cls._instances: cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) return cls._instances[cls] class C(metaclass=Singleton): def __init__(self, ..

Read more

I have a function that can generate the input for one test and I want to invoke that function for some random number of times to send inputs to my testing_function with @pytest.mark.parametrize ## part that generates inputs needed import numpy as np def generate_proper_list(): return np.random.uniform(low=0.1, high=8.0, size=(np.random.randint(low=1,high=5,size=1)[0],4)) ### I would like to run ..

Read more

File c.py has a global variable COBJ of an instance of C (Singleton) class Singleton(type): _instances = {} def __call__(cls, *args, **kwargs): if cls not in cls._instances: cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) return cls._instances[cls] class C(metaclass=Singleton): def __init__(self, a, b): #… def get(self, x): # To be mocked/patched return …. COBJ = C(1, ‘z’) And ..

Read more

@pytest.mark.parametrize allows one to define multiple sets of arguments and fixtures at the test function or class. It looks like this means that pytest.mark.parametrize can mark a test to run with multiple sets of fixtures? I can find plenty examples of parametrizing arguments, but I can’t figure out how to parametrize different test functions using ..

Read more

Can anyone help me figure out why driver is coming back as a NoneType in my pytest.hookimpl fixture? Here is my conftest.py @pytest.fixture() def chrome_driver_init(request, path_to_chrome): driver = webdriver.Chrome(options=opts, executable_path=path_to_chrome) request.cls.driver = driver page_object_init(request, driver) driver.get(URL) driver.maximize_window() yield driver.quit() # Adds a screenshot to the pytest-html report for a failed test @pytest.hookimpl(hookwrapper=True) def pytest_runtest_makereport(item, call): ..

Read more

I am working on Unit testing of python code , where I want to mock header value , I have never done this before so not sure how its done. I have a Authentication key in my header and I am not sure what value has to be put there. It’s definitely some encoded key ..

Read more