一个鼻子插件,种子伪造包。
nose-seed-faker的Python项目详细描述
鼻子种子伪造者
一个鼻子插件,用于播种 faker基于测试名称的包。
$ nosetests --with-seed-faker mytests/
Faker是在每个测试开始时根据测试名称播种的,因此 每个使用faker的测试在测试运行之间将使用相同的假数据, 不考虑测试顺序。
这取决于 behavior 伪造者在全球范围内共享了一个随机实例 faker类的实例,因此植入faker的any实例将 种子everyfaker实例。
例如,这两个测试使用faker生成假电子邮件地址:
importunittestfromfakerimportFakerfake=Faker()classTestEmail(unittest.TestCase):deftest_one(self):email=fake.email()print(email)deftest_two(self):email=fake.email()print(email)
由于faker生成随机电子邮件地址,如果我们运行test_one 每次测试运行,我们都会使用不同的电子邮件:
$ nosetests -v --nocapture tests.py:TestEmail.test_one tests.py:TestEmail.test_one test_one (tests.TestEmail) ... opouros@hermistondeckow.com ok test_one (tests.TestEmail) ... sgrady@hotmail.com ok ---------------------------------------------------------------------- Ran 2 tests in 0.001s OK
虽然这有助于增加我们使用的电子邮件的表面积 我们的测试,可能会导致片状测试-测试可能会神秘地失败, 但是如果你试图再次运行它来调试失败,突然 又过去了!
nose-seed-faker通过基于 每个测试的名称。使用插件,如果运行同一个测试 它将使用相同的电子邮件地址:
$ nosetests --with-seed-faker -v --nocapture tests.py:TestEmail.test_one tests.py:TestEmail.test_one test_one (tests.TestEmail) ... mitchel07@yost.com ok test_one (tests.TestEmail) ... mitchel07@yost.com ok ---------------------------------------------------------------------- Ran 2 tests in 0.001s OK
每个单独的测试都会使用不同的电子邮件,所以我们仍然可以得到 测试中使用的电子邮件表面积:
$ nosetests --with-seed-faker -v --nocapture tests.py test_one (tests.TestEmail) ... mitchel07@yost.com ok test_two (tests.TestEmail) ... kurt.bartell@yahoo.com ok ---------------------------------------------------------------------- Ran 2 tests in 0.001s OK
安装
$ pip install nose-seed-faker
警告
faker的0.5.2和更低版本将为random模块种子 全球地。
版本0.5.3fixes 这个问题是通过植入random.Random类的实例来解决的,但是 在撰写本文时,这个修复程序还没有发布到pypi。
在pypi上发布0.5.3版本之前,您可以像这样安装:
$ pip install git+http://github.com/joke2k/faker.git@dabf922af72783ebd9d163611ab0f4f307156443#egg=fake-factory==0.5.3
历史记录
0.1.2
发布日期:2015-06-30
- 初始版本