pytest

pytest - Suppress DeprecationWarning from specific 3rd party modules

安稳与你 提交于 2019-12-24 05:22:38
问题 When I run pytest I'm getting some deprecation warnings from a 3rd party library. I'd like to be informed about any deprecation warnings in my own code, but not in a vendored copy of a library bundled with another 3rd-party library. This answer was helpful in getting me partway there. If I run pytest like this: $ pytest ./tests/ I get: $ pytest ./tests/ ============================= test session starts ============================== platform linux -- Python 3.7.4, pytest-5.2.1, py-1.8.0,

Using @mark.incremental and metafunc.parametrize in a pytest test class

喜你入骨 提交于 2019-12-24 02:34:18
问题 the purpose of @mark.incremental is that if one test fails, the tests afterwards are marked as expected to fail. However, when I use this in conjuction with parametrization I get undesired behavior. For example, in the case of this fake code: //conftest.py: def pytest_generate_tests(metafunc): metafunc.parametrize("input", [True, False, None, False, True]) def pytest_runtest_makereport(item, call): if "incremental" in item.keywords: if call.excinfo is not None: parent = item.parent parent.

Is there a way to run a method automatically on the initialization of an instance without using __init__?

ぐ巨炮叔叔 提交于 2019-12-24 02:33:37
问题 I am writing some unit tests with Pytest. If I want them to be collected automatically, I have to avoid the __init__ constructor. (If there's a way to make Pytest collect tests with the __init__ constructor I'd take that as an alternate useful answer.) My unit tests have some variables and methods in common. Right now I have base test class TestFoo, and child test class TestBar(TestFoo), and grandchild test class TestBaz(TestBar). Since I can't have an init method, right now I'm calling a

Does pytest have anything like google test's non-fatal EXPECT_* behavior?

假如想象 提交于 2019-12-24 01:47:22
问题 I'm more familiar with the google test framework and know about the primary behavior pair they support about ASSERT_* vs EXPECT_* which are the fatal and non-fatal assert modes. From the documentation: The assertions come in pairs that test the same thing but have different effects on the current function. ASSERT_* versions generate fatal failures when they fail, and abort the current function. EXPECT_* versions generate nonfatal failures, which don't abort the current function. Usually

Can Pytest run at a pre-scheduled time?

橙三吉。 提交于 2019-12-24 01:01:49
问题 I am using pytest to run my tests using python3 script like below: pytest -s test_file.py | tee -a myoutput.log It works. Now I would like to run this at a specific time everyday, I tried "crontab -e" from linux console but failed. I mean there is no log added to "myoutput.log" file. Can anyone please help? thanks! 42 00 * * * /usr/bin/pytest pytest -s /data/smc/test_file.py | tee -a myoutput.log 回答1: I think it can be done by using cron output. eg: 42 00 * * * /usr/bin/pytest pytest -s /data

How can I make doctests triggered by pytest ignore unicode prefix `u'…'` of strings?

与世无争的帅哥 提交于 2019-12-23 21:07:23
问题 I want my code to work in Python 2 and 3. I use doctests and from __future__ import unicode_literals Is there a flag I can set / a plugin which makes it ignore that Python 2 has the u prefix for unicode strings? Example One test that works in Python 3, but fails in Python 2: Expected: 'Me \\& you.' Got: u'Me \\& you.' Minimal example from __future__ import unicode_literals def foo(): """ Returns ------- unicode - for Python 2 and Python 3 Examples -------- >>> foo() 'bar' """ return 'bar' if

ImportError shows up with py.test, but not when running the app

亡梦爱人 提交于 2019-12-23 20:22:14
问题 Unlike in this question: Importing modules from a sibling directory for use with py.test I can import something from my app, but there's an import error (looking like a circular dependency) that raises from 'inside' myapp while running the test and not when running myapp alone: $ python3 myapp/myapp.py Some dummy string (correct output) But: $ python3 -m pytest ================================================================= test session starts ===============================================

Running pytest tests in another Python package

巧了我就是萌 提交于 2019-12-23 19:55:28
问题 Right now, I have a Python package (let's call it mypackage ) with a bunch of tests that I run with pytest. One particular feature can have many possible implementations, so I have used the funcarg mechanism to run these tests with a reference implementation. # In mypackage/tests/conftest.py def pytest_funcarg__Feature(request): return mypackage.ReferenceImplementation # In mypackage/tests/test_stuff.py def test_something(Feature): assert Feature(1).works Now, I am creating a separate Python

initing a pytest fixture with a parameter

橙三吉。 提交于 2019-12-23 19:46:15
问题 I have a fixture that creates an object I use in many tests. This Object has a property - priority (1 - 10) Now, there are a lot of tests that need to "know" the priority of the object (in order to test various logic paths) So I could have 10 different fixtures: @pytest.fixture def object_priority_1(): return MyObj(priority=1) @pytest.fixture def object_priority_2(): return MyObj(priority=2) //.... @pytest.fixture def object_priority_10(): return MyObj(priority=10) But it seems off... I'm

Pytest: How to parametrize a test with a list that is returned from a fixture?

给你一囗甜甜゛ 提交于 2019-12-23 18:40:01
问题 I want to parametrize a test with a list which is created dynamically by a fixture like so: @pytest.fixture def my_list_returning_fixture(depends_on_other_fixtures): return ["a dynamically created list which", depends_on_other_fixtures] How can I achieve that? Alternatively, how can I ensure that a certain fixture gets called first - this would solve this problem before it even occurs. What I already tried I tried to parametrize the test with the fixture (which just results in errors because