【问题标题】:Test cases that run two different python scripts which are in different directories运行位于不同目录中的两个不同 python 脚本的测试用例
【发布时间】:2018-02-09 12:17:19
【问题描述】:

我想运行一个 .robot 文件来测试两个不同的 python 脚本,它们位于不同的目录中。我的 .robot 文件位于/home/alperen/Desktop/scpTest,内容如下:

*** Settings ***
| Library | Process

*** Test Cases ***
| Use Case 1 - Scp Test

| | [Documentation] | This .robot file tests the useCase1ScpTest.py by checking the stdout.

| | [Tags] | use case 1 | critical | scpTest

| | ${result}= | run process | python | /home/alperen/Desktop/scpTest/useCase1scpTest.py
| | Should be equal as integers | ${result.rc} | 0
| | Should be equal as strings | ${result.stdout} | Passed.


| Dummy test

| | [Documentation] | Dummy text

| | [Tags] | foo | bar | runScriptOnRemote

| | ${result}= | run process | python | /home/alperen/Desktop/runScriptOnRemote/masterScript.py
| | Should be equal as integers | ${result.rc} | 0
| | Should be equal as strings | ${result.stdout} | Passed.

如果我运行上面的代码,虚拟测试会失败并显示消息“失败。!= 通过。”因为 masterScript.py 最有可能打印“失败”。但是,如果我将 masterScript.py 与我的 .robot 文件复制到同一目录,则虚拟测试结果通过。谁能帮我理解为什么会这样?有没有办法在不复制 masterScript.py 的情况下通过虚拟测试?提前致谢。

编辑:masterScript.py 在远程机器上运行另一个名为 hello.py(打印“hello world”)的脚本。如果打印“hello world”,则 masterScript.py 文件打印“Passed”。和“失败”。否则。

【问题讨论】:

  • masterScript.py 是做什么的?它确实可以打印“失败”。在一个目录中并“通过”。在另一个。
  • 您是否尝试过从两个目录手动启动 masterScript?输出是什么?
  • 仅从/home/alperen/Desktop/runScriptOnRemote 运行 masterScript.py 即可。但是,从 /home/alperen/Desktop/scpTest 运行它会打印以下内容:couldn't read file "hello.py": no such file or directory 和“失败”。

标签: testing automated-tests robotframework


【解决方案1】:

我修改了 masterScript.py,其中包含类似

command = [ "python", "hello.py" ]

感谢 Psytho 的建议,将 "hello.py" 更改为其完整目录,类似于 "/home/alperen/Desktop/runScriptOnRemote/hello.py" 的工作。

【讨论】:

    【解决方案2】:

    使用 --pythonpath 开关将机器人运行到 masterScript.py 路径。这不是最优雅的解决方案,但它确实有效

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-18
      • 2021-11-03
      • 1970-01-01
      • 2020-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多