pytest的竞争条件测试

pytest-race的Python项目详细描述


https://github.com/idlesign/pytest-race

https://img.shields.io/pypi/v/pytest-race.svghttps://img.shields.io/pypi/dm/pytest-race.svghttps://img.shields.io/pypi/l/pytest-race.svghttps://img.shields.io/coveralls/idlesign/pytest-race/master.svghttps://img.shields.io/travis/idlesign/pytest-race/master.svghttps://landscape.io/github/idlesign/pytest-race/master/landscape.svg?style=flat

说明

pytest的竞赛条件测试仪

引入start_race运行竞赛条件测试的fixture。

要求

  • Python2.7+,3.3+
  • Pytest 2.9.0+

用法

您可以在测试中使用start_race夹具,如下所示:

fromtimeimportsleepACCUMULATOR=0# This global var is race conditions prone.deftest_race(start_race):fromrandomimportrandintdefactual_test():globalACCUMULATORincrement=randint(1,10000)accumulator=ACCUMULATORsleep(1)# Simulate some lag.ACCUMULATOR+=increment# By that moment ACCUMULATOR should have been updated# by another thread. Let's try to prove it.# Using simple `assert` as usual for pytest.assertaccumulator+increment==ACCUMULATOR# Let's run `actual_test` in 2 threads.start_race(threads_num=2,target=actual_test)

start_race接受以下参数:

  • threads_num-要同时运行的线程数。
  • target-可在线程中运行的实际测试调用。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaFX进度条从单独的函数更改而来   jvm使用java服务器选项   java在<li>元素中查找同名的最后一个链接   java问题将参数传递给不同公共类中的构造函数   如何在php中从java函数中获取字符串   java如何在Android中动态显示多个tile   java仅使用Ribbon而不使用任何服务注册表是否可以实现负载平衡?   Jersey 1.19版本的java Swagger JAXRS出现“冲突URI模板”错误   带H2数据库的java Spring boot jpa   从12:00:00到00:00:00的日期转换   Android中的java如何设置文本?   java密钥库“不支持的保护参数”   http使用Java在Java中发送httprequest。净包   SpringJava刷新数据库   java在Spring Boot应用程序中使用嵌入式MongoDb和MongoTemplate失败   java需要什么MatOfMatch对象?   xml使用Java中的合并算法将两个值合并为单个值   java SQLite数据库不保存数据为什么不工作