pytest

软件测试开发实战|接口自动化测试框架开发(pytest+allure+aiohttp+用例自动生成)

寵の児 提交于 2020-12-11 08:41:36
近期准备优先做接口测试的覆盖,为此需要开发一个测试框架,经过思考,这次依然想做点儿不一样的东西。 接口测试是比较讲究效率的,测试人员会希望很快能得到结果反馈,然而接口的数量一般都很多,而且会越来越多,所以提高执行效率很有必要 接口测试的用例其实也可以用来兼做简单的压力测试,而压力测试需要并发 接口测试的用例有很多重复的东西,测试人员应该只需要关注接口测试的设计,这些重复劳动最好自动化来做 pytest和allure太好用了,新框架要集成它们 接口测试的用例应该尽量简洁,最好用yaml,这样数据能直接映射为请求数据,写起用例来跟做填空题一样,便于向没有自动化经验的成员推广 加上我对Python的协程很感兴趣,也学了一段时间,一直希望学以致用,所以http请求我决定用aiohttp来实现。 但是pytest是不支持事件循环的,如果想把它们结合还需要一番功夫。于是继续思考,思考的结果是其实我可以把整个事情分为两部分。 第一部分,读取yaml测试用例,http请求测试接口,收集测试数据。 第二部分,根据测试数据,动态生成pytest认可的测试用例,然后执行,生成测试报告。 这样一来,两者就能完美结合了,也完美符合我所做的设想。想法既定,接着 就是实现了。 第一部分(整个过程都要求是异步非阻塞的) 读取yaml测试用例 一份简单的用例模板我是这样设计的,这样的好处是,参数名和aiohttp

How to access the py.test capsys from inside a test?

天涯浪子 提交于 2020-12-10 00:17:52
问题 py.test documentations says that I should add capsys parameter to my test methods but in my case this doesn't seem to be possible. class testAll(unittest.TestCase): def setUp(self): self.cwd = os.path.abspath(os.path.split(inspect.getfile(inspect.currentframe()))[0]) os.chdir(self.cwd) def execute(self, cmd, result=0): """ Helper method used by many other tests, that would prevent replicating too much code. """ # cmd = "%s > /dev/null 2>&1" % cmd ret = os.system(cmd) >> 8 self.assertEqual(ret

How to access the py.test capsys from inside a test?

北慕城南 提交于 2020-12-10 00:17:11
问题 py.test documentations says that I should add capsys parameter to my test methods but in my case this doesn't seem to be possible. class testAll(unittest.TestCase): def setUp(self): self.cwd = os.path.abspath(os.path.split(inspect.getfile(inspect.currentframe()))[0]) os.chdir(self.cwd) def execute(self, cmd, result=0): """ Helper method used by many other tests, that would prevent replicating too much code. """ # cmd = "%s > /dev/null 2>&1" % cmd ret = os.system(cmd) >> 8 self.assertEqual(ret

Transitive import error: ModuleNotFoundError: No module named '…'

拟墨画扇 提交于 2020-12-09 18:37:41
问题 I'm confused now. Here is the project tree: project - source - - lib - - - __init__.py - - - utils.py - - - stats.py - test - - lib - - - test_stats.py stats.py has import utils , which indeed works if one executes stats.py itself. Now test_stats.py has import lib.stats but that results in the ModuleNotFoundError: No module named 'utils' error if executed as PYTHONPATH=source pytest in the project directory: ==================================== ERRORS ==================================== ____

SQL Alchemy Won't Drop Tables at end of Test due to MetaData Lock on db

对着背影说爱祢 提交于 2020-12-06 13:51:16
问题 I am working on testing my flask app model. I'm using mysql 5.7, sqlalchemy and pytest. Within my model, I have a CRUD mixin that I used to manage creating, updating and deleting. Whenever I try to access the object in the Mixin before returning the object to the test function, SQLAlchemy hangs at db.drop_all in my tear down. When I look in mysql at PROCESSLIST, it shows 1 sleep query and 1 query waiting for table metadata lock. I can fix this by calling db.session.commit in the create method

SQL Alchemy Won't Drop Tables at end of Test due to MetaData Lock on db

ε祈祈猫儿з 提交于 2020-12-06 13:50:32
问题 I am working on testing my flask app model. I'm using mysql 5.7, sqlalchemy and pytest. Within my model, I have a CRUD mixin that I used to manage creating, updating and deleting. Whenever I try to access the object in the Mixin before returning the object to the test function, SQLAlchemy hangs at db.drop_all in my tear down. When I look in mysql at PROCESSLIST, it shows 1 sleep query and 1 query waiting for table metadata lock. I can fix this by calling db.session.commit in the create method

Fixture “setUp” called directly. Fixtures are not meant to be called directly

旧时模样 提交于 2020-12-06 12:16:38
问题 Commandline python3 -m pytest src/spec/ --app=android conftest.py import pytest def pytest_addoption(parser): parser.addoption('--app') @pytest.fixture(scope="session") def app(request): return request.config.getoption("--app") driver.py import pytest class Driver(unittest.TestCase): def __init__(self, driver): unittest.TestCase.__init__(self, driver) @pytest.fixture(autouse=True) def setUp(self, app): self.app = app if self.app == 'ios': desired_caps = {} desired_caps['platformName'] = 'ios'

Testing Spark with pytest - cannot run Spark in local mode

三世轮回 提交于 2020-12-06 08:02:48
问题 I am trying to run wordcount test using pytest from this site - Unit testing Apache Spark with py.test. The problem is that I cannot start spark context. Code I use to run Spark Context: @pytest.fixture(scope="session") def spark_context(request): """ fixture for creating a spark context Args: request: pytest.FixtureRequest object """ conf = (SparkConf().setMaster("local[2]").setAppName("pytest-pyspark-local-testing")) sc = SparkContext(conf=conf) request.addfinalizer(lambda: sc.stop()) quiet

Testing Spark with pytest - cannot run Spark in local mode

一世执手 提交于 2020-12-06 08:02:46
问题 I am trying to run wordcount test using pytest from this site - Unit testing Apache Spark with py.test. The problem is that I cannot start spark context. Code I use to run Spark Context: @pytest.fixture(scope="session") def spark_context(request): """ fixture for creating a spark context Args: request: pytest.FixtureRequest object """ conf = (SparkConf().setMaster("local[2]").setAppName("pytest-pyspark-local-testing")) sc = SparkContext(conf=conf) request.addfinalizer(lambda: sc.stop()) quiet

Python自动化测试从何学起?京东测试经理规划的学习路线,你不点进来看看?

自古美人都是妖i 提交于 2020-12-04 09:57:55
学习路线规划 前言 一、学习Python基本语法 二、掌握WebUI自动化测试 三、掌握AppUi自动化测试 四、掌握接口自动化测试 前言 作为软件测试人,从事手工测试的工作是没有太多坏处的,但是很显然如果一直点来点去那么确实自身得不到提高,那这时候选择学习自动化测试是一件很有必要的事情,一来将自己从繁重的重复工作中解放出来,从事一些更有挑战的工作,二来能积累技术知识,厚积薄发完成飞跃,那么技术新人该如何学习自动化测试呢? 一、学习Python基本语法 基本的语言知识,语法、函数、模块、输入与输出、面向对象编程 脚本编写、标准库、多线程、第三方库,外部数据处理 unittest、pytest测试框架、参数化、数据驱动 二、掌握WebUI自动化测试 selenium安装、录制、处理 web控件、JavaScript脚本、PO模式 三、掌握AppUi自动化测试 appium使用、录制、元素定位方法 APP控件定位、交互,参数化用例 appium问题定位分析、源码分析、二次封装 四、掌握接口自动化测试 接口自动化测试框架request 接口请求构造、断言 json/xml请求、响应断言 headcookie处理、认证体系 真正学会这些知识之后,出去找工作1w起步!写完这些之后,我还给各位想要学习Python自动化测试的朋友,整理了测试资料以及自动化测试的面试题放在我的内部群里