Skip to content
Advertisement

Tag: pytest

Provide default argument value for py.test fixture function

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

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

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

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

Advertisement