fixtures可以自检请求的测试上下文
fixtures函数可以接受request对象来自检“requesting”测试函数、类或模块上下文。进一步扩展之前的smtp_connection示例,从使用的测试模块中读取一个可选的服务器URL:

我们使用request.module属性从测试模块中选择获取smtpserver属性,如果再次执行,什么都不变:


创建另一个测试模块,该模块实际上在其模块命名空间中增加了服务器URL设置:

执行结果:

可以看出,smtp_connection 函数从模块命名空间中获取的邮件服务器名称。
网友评论