我最近又回到了python中,我有点生疏了。我已经开始使用测试框架鼻子了。我试图找出可用于此框架的可能功能。
例如,当我在ruby中使用rspec时,如果我想在编写测试用例时找到可用的“选项”,我只需转到下面的链接并浏览doco,直到找到我需要的内容:
https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/comparison-matchers
现在,当我尝试为鼻子做同样的事情时,谷歌一直把我送到:
https://nose.readthedocs.io/en/latest/writing_tests.html#test-functions
虽然doco信息丰富,但它并不是我想要的。
是否有一个python命令可用于查找可能的测试选项或其他存储最新文档的地方?
答案 0 :(得分:1)
应记录所有鼻子/单元测试提供的断言:
https://docs.python.org/2.7/library/unittest.html
除了doc之外,代码总是说实话。您可以查看库源代码,或者放入测试方法中的调试器:
#!/bin/bash -u
# Takes 1 argument. Aborts the script if there's a false negative.
function mysql_db_exists () {
local DBNAME="$1"
# Underscores are treated as wildcards by mysqlshow.
# Replace them with '\\_'. One of the underscores is consumed by the shell to keep the one mysqlshow needs in tact.
ESCAPED_DB_NAME="${DBNAME//_/\\\_}"
RESULT="$(mysqlshow "$ESCAPED_DB_NAME" 2>&1)"; EXITCODE=$?
if [ "$EXITCODE" -eq 0 ]; then
# This is never a false positive.
true
else
if echo "$RESULT" | grep -iq "Unknown database"; then
# True negative.
false
else
# False negative: Spit out the error and abort the script.
>&2 echo "ERR (mysql_db_exists): $RESULT"
exit 1
fi
fi
}
if mysql_db_exists "$1"; then
echo "It definitely exists."
else
echo "The only time you see this is when it positively does not."
fi
然后检查测试方法是否有可用的断言。
import pdb; pdb.set_trace()
dir(self)