difference between fixture and yield_fixture in pytest

The only difference is in readability. I think (though I’m not 100% sure) the underlying behavior is identical (i.e. the cleanup after the yield statement is run as a finalizer). I always prefer using yield fixtures for cleanup, since it’s more readable. If you’re using pytest <3.0, you’ll still need to use pytest.yield_fixture to get … Read more

Can I perform multiple assertions in pytest?

As Jon Clements commented, you can fill a list of error messages and then assert the list is empty, displaying each message when the assertion is false. concretely, it could be something like that: def test_something(self): errors = [] # replace assertions by conditions if not condition_1: errors.append(“an error message”) if not condition_2: errors.append(“an other … Read more

Writing a pytest function for checking the output on console (stdout)

Use the capfd fixture. Example: def test_foo(capfd): foo() # Writes “Hello World!” to stdout out, err = capfd.readouterr() assert out == “Hello World!” See: http://pytest.org/en/latest/fixture.html for more details And see: py.test –fixtures for a list of builtin fixtures. Your example has a few problems. Here is a corrected version: def f(name): print “hello {}”.format(name) def … Read more

How to skip a pytest using an external fixture?

It seems py.test doesn’t use the test fixtures when evaluating the expression for skipif. By your example, test_ios is actually successful because it is comparing the function platform found in the module’s namespace to the “ios” string, which evaluates to False hence the test is executed and succeeds. If pytest was inserting the fixture for … Read more

Async fixtures with pytest

You only need to mark your tests as async @pytest.mark.asyncio async def test_app(create_x, auth): api_client, x_id = create_x resp = await api_client.get(f’my_res/{x_id}’, headers=auth) assert resp.status == web.HTTPOk.status_code This tells pytest to run the test inside an event loop rather than calling it directly. The fixtures can be marked as normal @pytest.fixture async def create_x(api_client): x_id … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)