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的更多相关文章

  1. Robot Framework 源码阅读 day1 __main__.py

    robot文件夹下的__main__.py函数 是使用module运行时的入口函数: import sys # Allows running as a script. __name__ check n ...

  2. Robot Framework 源码阅读 day2 TestSuitBuilder

    接上一篇 day1 run.py 发现build test suit还挺复杂的, 先从官网API找到了一些资料,可以看出这是robotframework进行组织 测试案例实现的重要步骤, 将传入的te ...

  3. Robot Framework 源码解析(1) - java入口点

    一直很好奇Robot Framework 是如何通过关键字驱动进行测试的,好奇它是如何支持那么多库的,好奇它是如何完成截图的.所以就打算研究一下它的源码. 这是官方给出的Robot framework ...

  4. Robot Framework源码解析(2) - 执行测试的入口点

    我们再来看 src/robot/run.py 的工作原理.摘录部分代码: from robot.conf import RobotSettings from robot.model import Mo ...

  5. Spring源码阅读笔记

    前言 作为一个Java开发者,工作了几年后,越发觉力有点不从心了,技术的世界实在是太过于辽阔了,接触的东西越多,越感到前所未有的恐慌. 每天捣鼓这个捣鼓那个,结果回过头来,才发现这个也不通,那个也不精 ...

  6. Django之REST framework源码分析

    前言: Django REST framework,是1个基于Django搭建 REST风格API的框架: 1.什么是API呢? API就是访问即可获取数据的url地址,下面是一个最简单的 Djang ...

  7. Bert源码阅读

    前言 对Google开源出来的bert代码,来阅读下.不纠结于代码组织形式,而只是梳理下其训练集的生成,训练的self-attention和multi-head的具体实现. 训练集的生成 主要实现在c ...

  8. vnpy源码阅读学习(1):准备工作

    vnpy源码阅读学习 目标 通过阅读vnpy,学习量化交易系统的一些设计思路和理念. 通过阅读vnpy学习python项目开发的一些技巧和范式 通过vnpy的设计,可以用python复现一个小型简单的 ...

  9. python3 源码阅读-虚拟机运行原理

    阅读源码版本python 3.8.3 参考书籍<<Python源码剖析>> 参考书籍<<Python学习手册 第4版>> 官网文档目录介绍 Doc目录主 ...

随机推荐

  1. Comet OJ - Contest #4 D求和 思维题

    Code: #include <bits/stdc++.h> #define setIO(s) freopen(s".in","r",stdin) ...

  2. 解决报错(Could not create connection to database server.)

    org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory 尝试多种方法后发现是由于mysq ...

  3. BP神经网络设计

    1.网络层数 大部分单个隐藏层即可 2.输入层神经元个数 输入变量的个数通常都是由问题的外部描述所确定的.例如,如果有4个外部变量作为网络的输入,那么网络就有4个输入.但是,这是不是意味着输入层的神经 ...

  4. Linux内核调试方法总结之内核通知链

    Linux内核通知链notifier 1.内核通知链表简介(引用网络资料)    大多数内核子系统都是相互独立的,因此某个子系统可能对其它子系统产生的事件感兴趣.为了满足这个需求,也即是让某个子系统在 ...

  5. Week6 - 676.Implement Magic Dictionary

    Week6 - 676.Implement Magic Dictionary Implement a magic directory with buildDict, and search method ...

  6. mac, ios 模拟器

    genymotion  最好的android 硬件模拟器. 可多开,可gps定位,可模拟重力系统,可模拟磁场系统,模拟器海拔高度. 甚至可以模拟sd卡. 直接就等于真机. virtualbox 最好的 ...

  7. oracle 11g 数据库恢复技术 ---01 重做日志

    一 redo log Oracle数据库中的三大核心文件分别是数据文件(data file).重做日志(redo log)和控制文件(control file).数据文件保证了数据库的持久性,是保存修 ...

  8. 通过命令直接修改jar包中的静态文件

    1.先将要修改的jar包备份 copy xxx.jar xxx.jar_bak 2.建立一个新的目录便于后面的打包 mkdir jar_tmp 3.将包放到刚刚创建的目录里解压 mv xxx.jar ...

  9. Postman + Newman 生成测试报告

    1.安装Node.js 下载地址: https://nodejs.org/download/ 2.安装Newman 1) 打开cmd,输入:npm install -g newman 2) 安装支持N ...

  10. virutalenv一次行安装多个requirements里的文件