我有一个脚本可以根据用户定义的模板生成一堆pytest友好测试(py脚本)。
我想在这个生成的脚本中嵌入所有测试和逻辑,并对它进行pytest运行。这包括接收命令行参数并适当地解析它们。简而言之,是否可以使用pytest执行以下操作?
convenience init?(placeData: [String: Any], place: PTPlace? = nil) {
var start: Date?
var end: Date?
let formatter = DateFormatter()
for (key, value) in placeData {
let period = value as! [String: Any]
if key == "open" {
start = try? formatter.upcoming_date(with: period)
} else if key == "close" {
end = try? formatter.upcoming_date(with: period)
} else {
break // I'm not sure why you're doing this; it seems extremely imprudent (esp since dictionaries are not ordered)
}
}
if let start = start, let end = end {
self.init(start: start, end: end, place: place)
} else {
print("either start or end were not found")
return nil
}
}
等...
def test_1():
# some tests
def test_2():
# some more tests