如何在monkeyrunner测试文件中导入py文件函数

发布于 2024-12-26 03:21:19 字数 364 浏览 4 评论 0原文

我想在 Monkeyrunner 中为我的 Android 应用程序创建测试用例。

我正在考虑在实际测试用例之前创建一个子测试用例文件。与 install 、 uninstall 函数一样,它们位于单独的 py 文件中。我如何在 Monkeyrunner 测试用例中调用这些安装/卸载 apk 或任何其他函数?

我有一个成功的实验,从 PYTHON 中我的 py 文件中的其他导入的 py 文件调用函数。但在运行 Monkeyrunner 时无法调用相同的函数。

import new
print new.foo()

这在通过 python 运行时有效,但在 Monkeyrunner 中无效。 有什么解决办法吗?

I want to create test cases for my Android application in Monkeyrunner.

I am thinking to create a sub tests case file to do before actual test case. like a install , uninstall functions in a separate py file. How can i call these install/uninstall apk or any other function in my monkeyrunner test case?

I have a successful experiment of calling a function from other imported py file in my py file in PYTHON. but same function cannot called while running through monkeyrunner.

import new
print new.foo()

this is working while running through python but not working in monkeyrunner.
Any solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰之心 2025-01-02 03:21:19

Monkeyrunner (jython) 和 python 应该以完全相同的方式导入模块,唯一的区别可能是模块搜索路径的内容。
要验证它,请尝试:

   import sys
   print sys.path

在 python 和 Monkeyrunner 中,看看是否有任何差异。
如果你想包含一些路径, do

   sys.path.append("/path/to/my/new/module")
   import new
   print new.foo()

并且应该可以工作。

monkeyrunner (jython) and python should import modules exactly the same way, the only difference might be the content of the module search path.
To verify it try:

   import sys
   print sys.path

in both python and monkeyrunner and see if there are any differences.
If you want to include some path, do

   sys.path.append("/path/to/my/new/module")
   import new
   print new.foo()

and should work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文