Is there a way to specify which pytest tests to run from a file?

前端 未结 8 568
长情又很酷
长情又很酷 2020-12-12 11:05

Is there a way to select pytest tests to run from a file? For example, a file foo.txt containing a list of tests to be executed:

tes         


        
相关标签:
8条回答
  • 2020-12-12 11:58

    Here's a possible partial answer, because it only allows selecting the test scripts, not individual tests within those scripts.

    And it also limited by my using legacy compatibility mode vs unittest scripts, so not guaranteeing it would work with native pytest.

    Here goes:

    1. create a new dictory, say subset_tests_directory.
    2. ln -s tests_directory/foo.py
    3. ln -s tests_directory/bar.py

    4. be careful about imports which implicitly assume files are in test_directory. I had to fix several of those by running python foo.py, from within subset_tests_directory and correcting as needed.

    5. Once the test scripts execute correctly, just cd subset_tests_directory and pytest there. Pytest will only pick up the scripts it sees.

    Another possibility is symlinking within your current test directory, say as ln -s foo.py subset_foo.py then pytest subset*.py. That would avoid needing to adjust your imports, but it would clutter things up until you removed the symlinks. Worked for me as well.

    0 讨论(0)
  • 2020-12-12 12:03

    Maybe using pytest_collect_file() hook you can parse the content of a .txt o .yaml file where the tests are specify as you want, and return them to the pytest core.

    A nice example is shown in the pytest documentation. I think what you are looking for.

    0 讨论(0)
提交回复
热议问题