pytest

Pytest fixture with scope “class” running on every method

本秂侑毒 提交于 2019-12-11 03:26:55
问题 I'm trying to create a test environment with Pytest. The idea is to group test methods into classes. For every class/group, I want to attach a config fixture that is going to be parametrized. So that I can run all the tests with "configuration A" and then all tests with "configuration B" and so on. But also, I want a reset fixture, that can be executed before specific methods or all methods of a class. The problem I have there is, once I apply my reset fixture (to a method or to a whole class

Collecting and Reporting pytest Results

和自甴很熟 提交于 2019-12-11 02:57:17
问题 I am doing some Selenium testing via pytest. The next step is to start doing some reporting. I'd like to write something that allows me to run the tests, collect the results and send out an email. So far the closest thing that I've found to this is writing out the test result to the result log and then use a plugin to check the exist status and send an email from there. This works but is slightly cumbersome and I'm hoping that there is a more elegant way to do it. While the overall pytest

Running pytest-qt on CircleCI

左心房为你撑大大i 提交于 2019-12-11 02:09:48
问题 I am attempting to run tests which require pytest-qt (for testing PySide2 dialogs) on CircleCI. I am getting the following error: xdpyinfo was not found, X start can not be checked! Please install xdpyinfo! ============================= test session starts ============================== platform linux -- Python 3.6.8, pytest-5.0.0, py-1.8.0, pluggy-0.12.0 -- /home/circleci/project-caveman/venv/bin/python3 cachedir: .pytest_cache PySide2 5.13.0 -- Qt runtime 5.13.0 -- Qt compiled 5.13.0

Flask unit testing - How to reset app.url_map for each test?

时间秒杀一切 提交于 2019-12-11 02:08:15
问题 I'm writing a series of unit tests for a Flask app. The setup for each test is as follows: Create a Flask app in testing mode ( app.testing = True ). Mount a test endpoint (route) on a blueprint within the test app. (Then, exercise some tests on the endpoint...) The problem is that the app instance used in my tests accumulates the routes added from the previous tests instead of starting from a clean slate. It's as if app.url_map is never reset even though I create a new app each time... Here

Pytest/Allure - How to generate testcase description?

萝らか妹 提交于 2019-12-11 01:49:38
问题 I'm still fairly new to Allure, and I'm trying to generate a test description in my reports. Looking at other SO questions and pytest-allure-adaptor documentation, there doesn't seem to be an option to do this. The closest I've gotten was writing this: def test_one(): """ This is the test description. """ assert pass And that's very limited, since it automatically collapses it. In the Allure example report, you can see that they can use headers and probably markdown of some sort. How do I do

How to add stdin interaction with pytest

偶尔善良 提交于 2019-12-11 00:26:16
问题 I am writing integration tests for a system where I can automate most of the test via web service calls, but due to legacy-ness that I cannot change, I need a few steps to be done by manual testers. I wanted to use pytest and create a fixture that essentially pauses test execution and prompts the console for input (e.g. "Do XYZ in system; type 'done' when done") and continues with the remainder of the test. I admittedly haven't done a ton of hacking on this yet, but I see from pytest docs

Passing (yield) fixtures as test parameters (with a temp directory)

十年热恋 提交于 2019-12-11 00:15:07
问题 Question Is it possible to pass yielding pytest fixtures (for setup and teardown) as parameters to test functions? Context I'm testing an object that reads and writes data from/to files in a single directory. That path of that directory is saved as an attribute of the object. I'm having trouble achieve both of the follow: use a temporary directory with my test; and make sure that the directory is removed after each test. Example Consider the following (test_yieldfixtures.py): import pytest,

Double parameterization

我只是一个虾纸丫 提交于 2019-12-10 23:29:26
问题 So I have a set of tests where I'd like to test multiple versions of a solution. Currently I have import pytest import product_not_at_index functions_to_test = [ product_not_at_index.product_not_at_index_n_squared, product_not_at_index.product_not_at_index, ] def run_test(function_input, expected_result, test_func): actual_result = test_func(function_input) assert actual_result == expected_result @pytest.mark.parametrize("test_func", functions_to_test) def test_empty_list(test_func): input

py.test: get KeyboardInterrupt to call teardown

核能气质少年 提交于 2019-12-10 22:04:47
问题 I am using py.test to write some tests and in my tests I utilize funcargs. These funcargs have their own setups and teardowns defined in the conftest.py like this: conftest.py: def pytest_funcarg__resource_name(request): def setup(): # do setup def teardown(): # do teardown My problem is when someone uses CTRL+C to stop the test executions it leaves everything un-teardowned. I know there is a hook pytest_keyboard_interrupt but I dont know what to do from there. Sorry for the noobish question.

Mock exception raised in function using Pytest

大憨熊 提交于 2019-12-10 21:31:33
问题 I have the following function and it is a generic function which will make API call based on the input hostname and data. It will construct http request to make API and will return the response. This function will throw four types of exception(invalid URL, timeout, auth error and status check). How can I Mcok and Test the exception raised in API call using pytest? Which will be the best method to test the exceptions raised from API call? import ssl import urllib import urllib.request import