如何从我的功能文件中 运行 dev_appserver.py 行为 python?

How do I run dev_appserver.py from within my feature file in behave python?

dev_appserver.py 启动我的应用引擎服务的本地部署。我想 运行 我的测试在此本地服务上的行为。我想先在我的测试中启动服务器。如何在我的行为特征文件中 运行 dev_appsrrver.py app.yaml 命令开始?

我试过 subprocess.run("python","dev_appserver.py") 但它说找不到文件 dev_appserver.py。我正在试穿 windows。

引用App Engine documentation

To start the local development server:

  1. Run the dev_appserver.py command as follows from the directory that contains your app's app.yaml configuration file:

    Specify the directory path to your app, for example:

    dev_appserver.py [PATH_TO_YOUR_APP].

    Alternatively, you can specify the configuration file of a specific service, for example:

    dev_appserver.py app.yaml.

    To change the port, you include the --port option:

    dev_appserver.py --port=9999 [PATH_TO_YOUR_APP]

当您尝试使用 subprocess 方法启动可执行文件时,您通常不会默认获得相同的环境(执行路径和当前工作目录),您会进入 shell/terminal.这意味着您可能需要在传递给这些方法的参数列表中使用完整路径来引用文件(可执行文件和常规文件)。

由于 subprocess.run()dev_appserver.py 位置的执行投诉,这意味着它发现 python OK(您可能仍想检查它是否是 2.7 版本)并且您需要提供dev_appserver.py 的完整路径取决于您的 OS 和您使用的 SDK。例如在 Linux 上(抱歉,我不是 windows 人),路径是:

  • <GAE_SDK_dir>/dev_appserver.py 如果使用 GAE SDK
  • <gcloud_SDK_dir>/bin/dev_appserver.py 如果使用 gcloud SDK

您很可能还需要将路径传递给您的 GAE 应用程序的 app.yaml 文件 - 作为 dev_appserver.py 的参数,否则您会看到它抱怨无法找到应用程序或其文件(或者只是 运行 很糟糕 - 如果未指定 app.yaml 文件 dev_appserver.py 尝试自动检测它,但并非在所有情况下都有效)。我会避免并发症,只指定 app.yaml 个文件。

另请注意,subprocess.run() 参数应该是一个列表。像这样:

subprocess.run(['python', '<sdk_path_to>/dev_appserver.py', '<app_path_to>/app.yaml'])

另见 - post 是关于不同的可执行文件,但答案同样适用于 dev_appserver.py