Is there a better way for me to provide default value for argument pytest.fixture function? I have a couple of testcases that requires to run fixture_func before testcase and I would like to use default value for argument in fixture if none of them is provided. The only code I can come up with is as follows. Any better way
Tag: pytest
parametrize and running a single test in pytest
How can I run a single test out of a set configured with parametrize? Let’s say I have the following test method: I have 3 parameters, and I generate a list of 15 different possible values for them, to test the function on. How can I run just one of them? except for the obvious way – giving a single
py.test assert may raise, and if it raises it will be __
Is there pytest functionality similar to pytest.raises that passes iff the block raises the specified exception, or doesn’t raise at all? Something like: This question came up in the following situation.. The function to test: A couple of simple tests (fixtures below): The fixtures: the indicated <== problem is only a problem for test_encode_err() (and not test_encode_u8()), and happens since
pytest.mark.parameterize not “finding” fixtures
I’m writing tests for a small library and I decided to use py.test after hearing so many good things about it. However, pytest.mark.parameterize is giving me some issues. At first, I thought maybe I just mismatched some parens and it went off looking for a fixture elsewhere. So I decided to start with the given example of parameterize: But this
What’s the idea behind pytest-cache?
pytest-cache It seems to be a tool to cache func/args->result pairs and even persist them between testsuite-runs. Which seems like a great idea to speed things up. However I haven’t noticed any mention of automatically detecting a change of a function source code and invalidating corresponding cache entries. That seems to defeat the purpose of running the test suite, because
How to properly assert that an exception gets raised in pytest?
Code: Output: How to make pytest print traceback, so I would see where in the whatever function an exception was raised? Answer pytest.raises(Exception) is what you need. Code Output Note that e_info saves the exception object so you can extract details from it. For example, if you want to check the exception call stack or another nested exception inside.
PyCharm noinspection for whole file?
Is it possible to disable an inspection for the whole file in PyCharm? The reason this is needed is when dealing with py.test. It uses fixtures which appear to shadow function parameters, and at the same time cause unresolved references. e.g.: There is also other warnings from py.test, such as using pytest.raises() causes a “Can not find reference ‘raises'” in
py.test Tracebacks: Highlight my code, fold frames of framework
Tracebacks of my tests are too long since I use pytest. Pytests includes surrounding code lines and a lot of other information. I like to see this information if the traceback line (frame) is from my code. But I don’t want to see it, if it is from a library or framework. I could not find a way to filter
how to execute multiple tests on multiple items with py.test
I’m a novice in python and also in py.test. I’m searching a way to run multiple tests on multiple items and cannot find it. I’m sure it’s quite simple when you know how to do it. I have simplified what I’m trying to do to make it simple to understand. If I have a Test class who defines a serie
How to monkeypatch builtin function datetime.datetime.now?
I’d like to make sure that datetime.datetime.now() returns a specific datetime for testing purposes, How do I do this? I’ve tried with pytest’s monkeypatch But this gives me the error TypeError: can’t set attributes of built-in/extension type ‘datetime.datetime’ Answer As the error tells you, you can’t monkeypatch the attributes of many extension types implemented in C. (Other Python implementations may