Ask Your Question
3

What is the method to prevent Pytest from running the non-test Python file?

asked 2023-06-18 07:41:17 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-06-18 07:49:01 +0000

plato gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-18 07:41:17 +0000

Seen: 16 times

Last updated: Jun 18 '23