pytest

How to generate test report using pytest?

限于喜欢 提交于 2019-12-21 07:14:05
问题 How can I generate test report using pytest ? I searched for it but whatever i got was about coverage report. I tried with this command: py.test sanity_tests.py --cov=C:\Test\pytest --cov-report=xml But as parameters represents it generates coverage report not test report. Please help!! 回答1: Ripped from the comments: you can use the --junitxml argument. $ py.test sample_tests.py --junitxml=C:\path\to\out_report.xml 来源: https://stackoverflow.com/questions/29123840/how-to-generate-test-report

parametrizing test classes in pytest

試著忘記壹切 提交于 2019-12-21 07:08:32
问题 I have a class for testing some of my code. I would like to parametrize the setup and rerun the class with different parameters: class TestNormalLTEPlasma: def setup(self, t=10000): self.plasma = plasma.LTEPlasma.from_abundance(t, {'Si':1.0}, 1e-13, atom_data, 10*86400) def test_beta_rad(self): assert self.plasma.beta_rad == 1 / (10000 * constants.k_B.cgs.value) def test_t_electron(self): assert self.plasma.t_electron == 0.9 * self.plasma.t_rad def test_saha_calculation_method(self): assert

Use ipdb instead of pdb with py.test --pdb option

╄→尐↘猪︶ㄣ 提交于 2019-12-21 04:55:14
问题 I want to use ipdb instead of pdb with py.test --pdb option. Is this possible? If so, how? Clearly, I can use import ipdb; ipdb.set_trace() in the code but that requires to run the test, watch it fail, open a file, find the point of failure in said file, write the above line, re-run the tests. Lots of hassle if I could have something that by passes all of that. 回答1: Have you tried pytest-ipdb? Looks like it's exactly what you are looking for? 回答2: Use this option to set custom debugger: -

How to make pytest wait for (manual) user action?

守給你的承諾、 提交于 2019-12-21 04:03:19
问题 We are sucessfully using pytest (Python 3) to run a test suite testing some hardware devices (electronics). For a subset of these tests, we need the tester to change the hardware arrangement, and afterwards change it back. My approach was to use a module-level fixture attached to the tests in question (which are all in a separate module), with two input calls: @pytest.fixture(scope="module") def disconnect_component(): input('Disconnect component, then press enter') yield # At this point all

pytest - specify log level from the CLI command running the tests

喜夏-厌秋 提交于 2019-12-21 02:50:35
问题 my team and I are using Pytest + Jenkins to automate our product testing. we have been using the standard Logging lib of python to get proper log messages during testing, before and after each test etc. we have multiple layers of logging, we log out ERROR, WARNING, INFO and DEBUG. the default value for our logger is INFO. we create the logger object in the primary setup of the tests, and pass it down to each object created, so all our logs go to the same logger. so far when we are developing

Does pytest parametrized test work with unittest class based tests?

筅森魡賤 提交于 2019-12-20 17:37:06
问题 I've been trying to add parametrized @pytest.mark.parametrize tests to a class based unittest. class SomethingTests(unittest.TestCase): @pytest.mark.parametrize(('one', 'two'), [ (1, 2), (2, 3)]) def test_default_values(self, one, two): assert one == (two + 1) But the parametrized stuff didn't kick in : TypeError: test_default_values() takes exactly 3 arguments (1 given) I've switched to simple class based tests (without unittest). But I'd like to know if anyone tried it and it worked. 回答1:

Does pytest parametrized test work with unittest class based tests?

我的梦境 提交于 2019-12-20 17:36:11
问题 I've been trying to add parametrized @pytest.mark.parametrize tests to a class based unittest. class SomethingTests(unittest.TestCase): @pytest.mark.parametrize(('one', 'two'), [ (1, 2), (2, 3)]) def test_default_values(self, one, two): assert one == (two + 1) But the parametrized stuff didn't kick in : TypeError: test_default_values() takes exactly 3 arguments (1 given) I've switched to simple class based tests (without unittest). But I'd like to know if anyone tried it and it worked. 回答1:

Running unit tests in parallel with pytest?

泪湿孤枕 提交于 2019-12-20 04:34:11
问题 How can I parallelize the execution of the unit tests written with pytest? Which tactics of parallelism can I choose from? 回答1: In order to run pytests in parallel you are going to need to install pytest-xdist. Please see the different parallelism tactics listed below, you can use any of those (however I can bet that one of those suits best for your particular case): pip install pytest-xdist # The most primitive case, sending tests to multiple CPUs: pytest -n NUM # Execute tests within 3

pytest running scenarios in the correct order in the class

核能气质少年 提交于 2019-12-20 04:25:19
问题 So I have the following structure: class Test(object): def test_1(self): pass def test_2(self): pass def test_3(self): pass it runs great, NOW I'm adding the "scenarios" (as it's recommended at pytest - A quick port of “testscenarios”): def pytest_generate_tests(metafunc): idlist = [] argvalues = [] for scenario in metafunc.cls.scenarios: idlist.append(scenario[0]) items = scenario[1].items() argnames = [x[0] for x in items] argvalues.append(([x[1] for x in items])) metafunc.parametrize

Is it possible to run tear down fixture only after all params runs?

吃可爱长大的小学妹 提交于 2019-12-20 03:33:32
问题 For instance if you have: @pytest.mark.parametrize('lang', ["EN", "FR"]) def test_whats_hot_quick_links_are_displayed(self, lang): # Do something here and i have this teardown fixture in conftest: @pytest.fixture(scope='function', autouse=True) def teardown_function(request): def execute_at_the_end(): logging.info("Ending Test Case...") database.clear() request.addfinalizer(execute_at_the_end) So how can i make the teardown function execute only after both EN and FR test runs are executed