3

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?

3
  • 2
    You could shorten it to t_... and change the discovery: see e.g. pytest.org/latest/example/pythoncollection.html Commented May 11, 2015 at 7:04
  • Not as pretty, but something to be considered. If you add that as an answer I'll give it an upvote at least. Commented May 11, 2015 at 7:06
  • 1
    There is also: pypi.org/project/pytest-relaxed Commented May 7, 2021 at 11:44

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks. I was a bit imprecise. I am refering to the test methods, not files. Still, UV, since I was unclear.
Ahh, perhaps I could set the discovery blob to * and it will work. Gotta run to a meeting, but will test later.
@TheUnfunCat check the above link, you can customize almost everything included the test methods names
I meant to replace test with nothing at all, instead of test, not spec or anything else.
Accepted until sb comes up with a way to use any python function as a test name. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.