The Unfun Cat
The Unfun Cat

Reputation: 31908

Avoid starting test names with "test_" in pytest?

I want to write descriptive names for my tests, which makes the names long.

Is it possible to avoid having to call a test test_<something> and instead use a decorator or something else? Or can this be done via some command line arguments?

Upvotes: 1

Views: 2739

Answers (1)

number5
number5

Reputation: 16433

You can set it in py.test config, e.g. treat all check_*.py as tests files and all functions like *_spec as tests:

# content of setup.cfg
# can also be defined in in tox.ini or pytest.ini file
[pytest]
python_files=check_*.py
python_functions=*_spec

See more at https://pytest.org/latest/example/pythoncollection.html#change-naming-conventions

Upvotes: 6

Related Questions