One method to prevent Pytest from running non-test Python files is by using naming conventions. Pytest only runs files with names that start with "test". This means that non-test files should be given names that do not start with "test", such as "main.py" or "utils.py".
Another method is by using the command-line option "-k" or "--keyword". This can be used to specify a keyword that is only present in the names of the test files that you want to run. For example, if all your test files have the word "test" in their name, you can use the command "pytest -k test" to run only those files.
Additionally, you can also use the "--ignore" option followed by the name of the directory or file that you want Pytest to ignore when searching for test files. For example, "pytest --ignore=mymodule" will ignore the "mymodule" directory or file.
Asked: 2023-06-18 07:41:17 +0000
Seen: 16 times
Last updated: Jun 18 '23