Skip to content

Instantly share code, notes, and snippets.

@sotayamashita
Last active August 28, 2019 08:34
Show Gist options
  • Save sotayamashita/62ab33aba24bb85b298c9f9bf786215c to your computer and use it in GitHub Desktop.
Save sotayamashita/62ab33aba24bb85b298c9f9bf786215c to your computer and use it in GitHub Desktop.
How does pip call Python.

前提

$ pyenv versions
  system (2.7.16)
  2.7.0
* 3.7.0 (set by /path/to/.pyenv/version)

Python 2.7.16 が呼ばれることを期待

$ python -m pip install -U robotframework
$ robot --version
Robot Framework 3.1.2 (Python 2.7.16 on darwin)

$ robot main.robot
[ ERROR ] Error in file 'path/to/main.robot': Importing test library 'path/to/DebugKeywords.py' failed: SyntaxError: invalid syntax (DebugKeywords.py, line 16)


Python 3.7.0 が呼ばれることを期待

$ python3 -m pip install -U robotframework
$ robot --version
Robot Framework 3.1.2 (Python 3.7.0 on darwin)

$ robot main.robot
[ ERROR ] hello
# main.robot
*** Settings ***
Library SeleniumLibrary
Library path/to/DebugKeywords.py
*** Test Cases ***
Main
# DebugKeywords 内の check 関数が呼ばれる
Check
# DebugKeywords.py
from robot.api import logger
from SeleniumLibrary.base import keyword
from robot.libraries.BuiltIn import BuiltIn
from SeleniumLibrary.base import LibraryComponent
class KeywordClass(LibraryComponent):
def __init__(self, ctx):
LibraryComponent.__init__(self, ctx)
@keyword
def check(self):
# f-string is only supported after v3.6.4
message = "hello"
logger.error(f"{message}")
class DebugKeywords(object):
ROBOT_LISTENER_API_VERSION = 2
def __init__(self):
self.ROBOT_LIBRARY_LISTENER = self
def start_suite(self, name, attributes):
sl = BuiltIn().get_library_instance('SeleniumLibrary')
sl.add_library_components([KeywordClass(sl)])
BuiltIn().reload_library('SeleniumLibrary')
self.added = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment