Robot Framework 源码阅读 day1 run.py
robot里面run起来的接口主要有两类
run_cli
def run_cli(arguments):
"""Command line execution entry point for running tests. :param arguments: Command line arguments as a list of strings. For programmatic usage the :func:`run` function is typically better. It has
a better API for that usage and does not call :func:`sys.exit` like this
function. Example:: from robot import run_cli run_cli(['--include', 'tag', 'path/to/tests.html'])
"""
RobotFramework().execute_cli(arguments)
run
def run(*datasources, **options):
"""Executes given Robot Framework data sources with given options. ... ... ... Example:: from robot import run run('path/to/tests.html', include=['tag1', 'tag2'])
with open('stdout.txt', 'w') as stdout:
run('t1.txt', 't2.txt', report='r.html', log='NONE', stdout=stdout) Equivalent command line usage:: robot --include tag1 --include tag2 path/to/tests.html
robot --report r.html --log NONE t1.txt t2.txt > stdout.txt
"""
return RobotFramework().execute(*datasources, **options)
我们择其一从 run往下走
return RobotFramework().execute(*datasources, **options)
RobotFramework 继承自Application
class RobotFramework(Application): Application基类位于 /robot/utils/applicaiton.py
execute 函数执行并进入main函数体,
def execute(self, *arguments, **options):
with self._logger:
self._logger.info('%s %s' % (self._ap.name, self._ap.version))
return self._execute(list(arguments), options)
#execute 调用私有函数 _execute 执行操作
def _execute(self, arguments, options):
try:
rc = self.main(arguments, **options)
except DataError as err:
return self._report_error(err.message, help=True)
except (KeyboardInterrupt, SystemExit):
return self._report_error('Execution stopped by user.',
rc=STOPPED_BY_USER)
except:
error, details = get_error_details(exclude_robot_traces=False)
return self._report_error('Unexpected error: %s' % error,
details, rc=FRAMEWORK_ERROR)
else:
return rc or 0
由于RobotFramwork重写了main() 函数, 所以跳到RobotFramework的main接口执行。
/robot/run.py
def main(self, datasources, **options):
print "Enter run.main"
settings = RobotSettings(options)
# print settings
LOGGER.register_console_logger(**settings.console_output_config)
LOGGER.info('Settings:\n%s' % unic(settings))
suite = TestSuiteBuilder(settings['SuiteNames'],
settings['WarnOnSkipped']).build(*datasources)
suite.configure(**settings.suite_config)
if settings.pre_run_modifiers:
suite.visit(ModelModifier(settings.pre_run_modifiers,
settings.run_empty_suite, LOGGER))
with pyloggingconf.robot_handler_enabled(settings.log_level):
result = suite.run(settings)
print result
LOGGER.info("Tests execution ended. Statistics:\n%s"
% result.suite.stat_message)
if settings.log or settings.report or settings.xunit:
writer = ResultWriter(settings.output if settings.log
else result)
writer.write_results(settings.get_rebot_settings())
return result.return_code
STEP 1.
[explian]:
settings = RobotSettings(options)
/robot/conf/settings.py 解析传入参数
class RobotSettings(_BaseSettings):
-->继承自 _BaseSettings, 没有单独的__init__ 与基类共用 __init. STEP 2.
suite = TestSuiteBuilder(settings['SuiteNames'],
settings['WarnOnSkipped']).build(*datasources) [explian]: class TestSuiteBuilder 会初始化StepBuilder
builder.build_steps/builder.build_step 解析suite里面包含的测试steps or step.
23 self._build_steps = builder.build_steps
24 self._build_step = builder.build_step
由TestSuiteBuilder.build 生成 TestSuite
/robot/running/builder.py
def build(self, *paths):
"""
:param paths: Paths to test data files or directories.
:return: :class:`~robot.running.model.TestSuite` instance.
"""
if not paths:
raise DataError('One or more source paths required.')
if len(paths) == 1:
return self._parse_and_build(paths[0])
root = TestSuite()
for path in paths:
root.suites.append(self._parse_and_build(path))
return root
STEP 3.
/robot/model/testsuite.py
suite.configure(**settings.suite_config)
一些配置参数下发
Robot Framework 源码阅读 day1 run.py的更多相关文章
- Robot Framework 源码阅读 day1 __main__.py
robot文件夹下的__main__.py函数 是使用module运行时的入口函数: import sys # Allows running as a script. __name__ check n ...
- Robot Framework 源码阅读 day2 TestSuitBuilder
接上一篇 day1 run.py 发现build test suit还挺复杂的, 先从官网API找到了一些资料,可以看出这是robotframework进行组织 测试案例实现的重要步骤, 将传入的te ...
- Robot Framework 源码解析(1) - java入口点
一直很好奇Robot Framework 是如何通过关键字驱动进行测试的,好奇它是如何支持那么多库的,好奇它是如何完成截图的.所以就打算研究一下它的源码. 这是官方给出的Robot framework ...
- Robot Framework源码解析(2) - 执行测试的入口点
我们再来看 src/robot/run.py 的工作原理.摘录部分代码: from robot.conf import RobotSettings from robot.model import Mo ...
- Spring源码阅读笔记
前言 作为一个Java开发者,工作了几年后,越发觉力有点不从心了,技术的世界实在是太过于辽阔了,接触的东西越多,越感到前所未有的恐慌. 每天捣鼓这个捣鼓那个,结果回过头来,才发现这个也不通,那个也不精 ...
- Django之REST framework源码分析
前言: Django REST framework,是1个基于Django搭建 REST风格API的框架: 1.什么是API呢? API就是访问即可获取数据的url地址,下面是一个最简单的 Djang ...
- Bert源码阅读
前言 对Google开源出来的bert代码,来阅读下.不纠结于代码组织形式,而只是梳理下其训练集的生成,训练的self-attention和multi-head的具体实现. 训练集的生成 主要实现在c ...
- vnpy源码阅读学习(1):准备工作
vnpy源码阅读学习 目标 通过阅读vnpy,学习量化交易系统的一些设计思路和理念. 通过阅读vnpy学习python项目开发的一些技巧和范式 通过vnpy的设计,可以用python复现一个小型简单的 ...
- python3 源码阅读-虚拟机运行原理
阅读源码版本python 3.8.3 参考书籍<<Python源码剖析>> 参考书籍<<Python学习手册 第4版>> 官网文档目录介绍 Doc目录主 ...
随机推荐
- Manacher模板( 线性求最长回文子串 )
模板 #include<stdio.h> #include<string.h> #include<algorithm> #include<map> us ...
- 牛飞盘队Cow Frisbee Team
老唐最近迷上了飞盘,约翰想和他一起玩,于是打算从他家的N头奶牛中选出一支队伍. 每只奶牛的能力为整数,第i头奶牛的能力为R i .飞盘队的队员数量不能少于 .大于N. 一支队伍的总能力就是所有队员能力 ...
- Linux入门 文本编辑器
Vim vi -r file # 在上次使用vi编辑时发生崩溃,恢复file 在编辑多个文件时候 :n 下一个文件 :e# 回到刚才编辑的文件 撤销操作 撤销前一个命令 输入"u" ...
- height设置百分比的条件
很多时候我们在给height设置百分比的时候不起作用, 这时候就要来谈谈什么情况下才起作用了 1)所有父级元素必须有高度: 2)必须是块级元素,行内元素不起作用: 3)ie9 以下 使用 positi ...
- [BZOJ3781]:小B的询问(离线莫队算法)
题目传送门 题目描述 小B有一个序列,包含$N$个$1~K$之间的整数.他一共有$M$个询问,每个询问给定一个区间$[L...R]$,求$\sum \limits_{i=1}^{K}c(i)^2$的值 ...
- jsp页面a标签URL转码问题
简单的办法只有一句话,在后台对传过来的字符串(value)加一句: String value = new String(value.getBytes("ISO-8859-1"),& ...
- Java语言支持的变量类型有哪几种
Java语言支持的变量类型有: 类变量:独立于方法之外的变量,用 static 修饰. 实例变量:独立于方法之外的变量,不过没有 static 修饰. 局部变量:类的方法中的变量. 实例: publi ...
- ora600
4节点RAC:版本oracle11.2.0.4 22:20——23:40发生ora600 alert日志: Errors in file /u01/app/oracle/diag/rdbms/orcl ...
- AOF — Redis 设计与实现
w AOF — Redis 设计与实现http://redisbook.readthedocs.io/en/latest/internal/aof.html
- SpringBoot设置SORS的几种方式
1. 原生支持 Application 启动类添加以下代码: import org.springframework.context.annotation.Bean;import org.springf ...