Python: 测试的约定名称

Python: convention name for a test

使用 unittest 模块时,在 Python 中是否有命名测试的约定。我知道从 unittest.TestCase 继承的 class 中的每个方法都应该从测试开始,但我想知道什么更好:

1.没有文档字符串的简短描述性名称

def test_for_a_date_on_a_weekday(self):
        customer_type = "Regular"
        dates = ["16Mar2009(mon)"]
    self.assertEquals(self.hotel_reservation_system.find_cheapest_hotel(customer_type, dates), "Lakewood")

2。单词测试后面的数字和解释测试的文档字符串。

def test_1(self):
    """Tests the cheapest hotel when the date is on a weekday.
    """
    customer_type = "Regular"
    dates = ["16Mar2009(mon)"]
    self.assertEquals(self.hotel_reservation_system.find_cheapest_hotel(customer_type, dates), "Lakewood")

哪个选项更可取,如果有我应该使用哪个选项?

Generally it is preferable to increase readability by :
    - choosing an adequate name     
    - describing how it works

选择您的名字,使其简短且具有描述性。为了可读性,使用 snake_case。例如:test_week_date.

始终在您的函数中包含文档字符串。如果名字不够清楚或者他不真正理解该方法的作用/她是如何做到的,这将允许 reader 获得所有必要的信息。

结论:带有文档字符串的简短描述性 (snake_case) 名称。