Category : pytest

Pytest has a decorator that allows you to pass metadata to tests. You can apply the decorator to a class, which will apply it to all tests within that class. You can also apply the decorator to individual tests, like so: @pytest.mark.resources(‘a’) class FooTests: … def test_stuff(self): pass @pytest.mark.resources(‘a’,’b’,’c’) def test_something(self): pass In this example, ..

Read more

I have a Pytest + Selenium project and I would like to use the logging module. However, when I set up logging in conftest.py like this @pytest.fixture(params=["chrome"], scope="class") def init_driver(request): start = datetime.now() logging.basicConfig(filename=’.test.log’, level=logging.INFO) if request.param == "chrome": options = ChromeOptions() options.add_argument("–start-maximized") web_driver = webdriver.Chrome(ChromeDriverManager().install(), options=options) if request.param == "firefox": web_driver = webdriver.Firefox(GeckoDriverManager().install()) request.cls.driver ..

Read more

I am new to pytest. I wish to create a test case for below function. def test(work,cat): trans = cat.get_last_trans() eff_date = work.eff_date trans_eff_Date = datetime.strptime(trans[‘eff date’]), ‘%m%d%y’) if trans[‘type’] == new and trans[‘closed’] and eff_date == trans_eff_Date: return True return False Source: Python..

Read more

I want to send a json with a POST request, to a specific endpoint to my server, in pytest. This is what i normally feed the server with curl: curl –header "Content-Type: application/json" –request POST –data ‘{"item":"ZycugK6yXdHgf8foQTUnKY.txt","method":"one"}’ 0.0.0.0:5000/convert And this is how i tried to recreate it in pytest: data = {"item": filename, "method": method} ..

Read more

I know the title is quite confusing, but for the sake of clarity, I created a sample of what I have to transpose: Let’s say I have this code in class_file.py class CarDealership: def allow_car_out_of_the_dealership(self, car): logger.info(f"Driving out of the dealership") drivers_license = car.driver.wallet.get_drivers_license() if drivers_license: try: allow_car_removal(car, drivers_license) except: deny_car_removal(car, drivers_license) I’m trying to ..

Read more