【发布时间】:2016-02-18 15:31:23
【问题描述】:
假设我有两个文件(test_file1.py、test_file2.py)用于使用py.test 进行集成测试。
test_file1.py 是这样的:
import datetime
import pytest
Datetime = datetime.datetime.now()
def test_connect():
#1st Query to a mysql database
#2nd Query to a mysql database
..
#N Query to a mysql database
现在我正在编写 test_file2.py,它是 test_file1.py 的扩展,但我不想编写与上述测试中相同的 mysql 查询。
我怎样才能让py.test继承上面的测试
并在执行py.test test_file2.py之后同时运行?
类似这样的东西(test_file2.py 内容):
import datetime
import pytest
from testDirectory import test_file1
Datetime = datetime.datetime.now()
def test_connect():
#Here should run all the tests from 'test_file1' somehow...
#1st new additional Query to a mysql database
#2nd new additional Query to a mysql database
..
#N new additional Query to a mysql database
谢谢!!
【问题讨论】:
标签: python unit-testing inheritance integration-testing pytest