简体   繁体   中英

Hiding class from the test name in pytest

I have a testclass inside a module. Both testclass and module have more or less the same name and I don't expect to have the second class in this module.

My pytest output looks like this:

test_vlans.py::TestVlan::test_normal[delete_vlans] PASSED                              [  4%]
test_vlans.py::TestVlan::test_normal[alter_vlans] PASSED                               [  8%]
test_vlans.py::TestVlan::test_normal[add_vlans] PASSED                                 [ 13%]
test_vlans.py::TestVlan::test_idempotence[delete_vlans] PASSED                         [ 17%]
...

Testclass:

class TestVlan(BasicTestScenario):
    target = "vlans"

I feel like TestVlan is redundant here. How to exclude class name from the test name?

From the naming conventions :

If tests are defined as methods on a class, the class name should start with “Test”, as in TestExample.

From that, I would assume (a) you don't have to call your class TestVlan but (b) you should start with Test , even though you don't have to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM