import file mismatch in pytest
In my case, it was missing __init__.py file in tests directory.
In my case, it was missing __init__.py file in tests directory.
This is a makeshift progress bar. It displays the “percentage of work” done so far — most probably, total completed tests by the total number of tests to run (that it precalculated at the start). If your tests ran for longer, you would probably see the number in the line changing as it crunches through … Read more
Using the norecursedirs option in pytest.ini or tox.ini can save a lot of collection time, depending on what other files you have in your working directory. My collection time is roughly halved for a suite of 300 tests when I have that in place (0.34s vs 0.64s). If you’re already using tox like I am, … Read more
You want pytest-xdist. I think Qxf2 explains it quite well: Qxf2 on Pytest-Xdist Their Linux command-line is slightly too verbose for my tastes though; I use: pytest -n <NUM> where <NUM> is the number of parallel workers.
Not sure if this solution was specific to my problem, but I simply add __init__.py to my tests folder and that solved the problem.
pytest gathers tests according to a naming convention. By default any file that is to contain tests must be named starting with test_, classes that hold tests must be named starting with Test, and any function in a file that should be treated as a test must also start with test_. If you rename your … Read more
This answer presents two compelling use-cases for a TestClass in pytest: Joint parametrization of multiple test methods belonging to a given class. Reuse of test data and test logic via subclass inheritance Joint parametrization of multiple test methods belonging to a given class. The pytest parametrization decorator, @pytest.mark.parametrize, can be used to make inputs available … Read more
Will was on the right path, you should use request.getfixturevalue to retrieve the fixture. But you can do it right in the test, which is simpler. @pytest.mark.parametrize(‘dirname, expected’, [ (‘dir1_fixture’, ‘expected1’), (‘dir2_fixture’, ‘expected2’)]) def test_directory_command(dirname, expected, request): result = my_package.directory_command(request.getfixturevalue(dirname)) assert result == expected Another way is to use lazy-fixture plugin: @pytest.mark.parametrize(‘dirname, expected’, [ (pytest.lazy_fixture(‘dir1_fixture’), … Read more
With indirect=True you can parametrize your fixture, False – default value. Example: import pytest @pytest.fixture def fixture_name(request): return request.param @pytest.mark.parametrize(‘fixture_name’, [‘foo’, ‘bar’], indirect=True) def test_indirect(fixture_name): assert fixture_name == ‘baz’ So this example generates two tests. First one gets from fixture_name value foo, because this fixture for this test runs with parametization. Second test gets bar … Read more
You can put your stuff in other modules and reference them using a pytest_plugins variable in your conftest.py: pytest_plugins = [‘module1’, ‘module2’] This will also work if your conftest.py has hooks on them.