从源代码里应该可以帮我解答一些问题:
1. 这些关键字怎么定义的,然后怎么对应到具体的库来执行的
2. 框架的逻辑组织架构是什么样的,能学到哪些东西
3. 有没有一些可以改进的地方
4. 用到了哪些语言特性和技巧
5. 其他一些思考
安装完之后的入口robot文件如下:
https://github.com/robotframework/robotframework/tree/master/src/bin
从Robot开始,Linux应该运行的文件是下面这个
robotframework/src/bin/robot
内容如下:
#!/usr/bin/env python
import sys
from robot import run_cli
# Multiprocessing guard
# https://github.com/robotframework/robotframework/issues/2315
if __name__ == '__main__':
run_cli(sys.argv[1:])
可以看到模块robot的run_cli才是真正的入口
而从robot模块可以看到:
https://github.com/robotframework/robotframework/blob/master/src/robot/__init__.py
from robot.rebot import rebot, rebot_cli
from robot.run import run, run_cli
from robot.version import get_version
__all__ = ['run', 'run_cli', 'rebot', 'rebot_cli']
__version__ = get_version()
其实run_cli是从robot.run模块导出的
找到模块文件:https://github.com/robotframework/robotframework/blob/master/src/robot/run.py
def run_cli(arguments, exit=True):
"""Command line execution entry point for running tests.
:param arguments: Command line options and arguments as a list of strings.
:param exit: If ``True``, call ``sys.exit`` with the return code denoting
execution status, otherwise just return the rc. New in RF 3.0.1.
Entry point used when running tests from the command line, but can also
be used by custom scripts that execute tests. Especially useful if the
script itself needs to accept same arguments as accepted by Robot Framework,
because the script can just pass them forward directly along with the
possible default values it sets itself.
Example::
from robot import run_cli
# Run tests and return the return code.
rc = run_cli(['--name', 'Example', 'tests.robot'], exit=False)
# Run tests and exit to the system automatically.
run_cli(['--name', 'Example', 'tests.robot'])
See also the :func:`run` function that allows setting options as keyword
arguments like ``name="Example"`` and generally has a richer API for
programmatic test execution.
"""
return RobotFramework().execute_cli(arguments, exit=exit)
run_cli是命令行执行的入口,对应到RobotFramework().execute_cli才是真正模块代码的入口
要知道RobotFramework().execute_cli是从哪里进入的,还要看看import了哪些模块
from robot.conf import RobotSettings
from robot.model import ModelModifier
from robot.output import LOGGER, pyloggingconf
from robot.reporting import ResultWriter
from robot.running import TestSuiteBuilder
from robot.utils import Application, unic
class RobotFramework(Application):
def __init__(self):
Application.__init__(self, USAGE, arg_limits=(1,),
env_options='ROBOT_OPTIONS', logger=LOGGER)
RobotFramework继承了Application,下面看看application到底有什么
https://github.com/robotframework/robotframework/blob/master/src/robot/utils/application.py
class Application(object):
def __init__(self, usage, name=None, version=None, arg_limits=None,
env_options=None, logger=None, **auto_options):
self._ap = ArgumentParser(usage, name, version, arg_limits,
self.validate, e