Using py.test with coverage doesn’t include imports

@hynekcer gave me the right idea. But basically the easiest solution lies somewhere else: Get rid of pytest-cov! Use coverage run –source jedi -m py.test coverage report instead!!! This way you’re just running a coverage on your current py.test configuration, which works perfectly fine! It’s also philosophically the right way to go: Make each program … Read more

parametrize and running a single test in pytest

You can specify the tests to run by using the -k flag for filtering tests that match a string expression. When using parametrize, pytest names each test case with the following convention: test_name[‘-‘ separated test inputs] for example test_name[First_test_value-Second_test_value-N_test_value] Selecting an specific test to run is a matter of putting all the above together for … Read more

In which order are pytest fixtures executed?

The easiest way to control the order in which fixtures are executed, is to just request the previous fixture in the later fixture. So to make sure b runs before a: @pytest.fixture(autouse=True, scope=”function”) def b(): pass @pytest.fixture(scope=”function”) def a(b): pass For details on the general fixture resolution order, see Maxim’s excellent answer below or have … Read more

How to run all PyTest assertions even if some of them fail?

As others already mentioned, you’d ideally write multiple tests and only have one assertion in each (that’s not a hard limit, but a good guideline). The @pytest.mark.parametrize decorator makes this easy: import pytest def parrot(i): return i @pytest.mark.parametrize(‘inp, expected’, [(0, 0), (1, 1), (2, 1), (2, 2)]) def test_parrot(inp, expected): assert parrot(inp) == expected When … Read more

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