python - 使用 -m 选项或复制到 Windows 中的不同路径位置时,无法使用嵌入式 python 运行覆盖工具
问题描述
我正在尝试使用从https://www.python.org/ftp/python/3.6.1/python-3.6.1-embed-amd64.zip下载的嵌入式 python 运行 python 覆盖工具 以下是我遵循的步骤使用覆盖模块运行测试代码。
1)下载python-3.6.1-embed-amd64.zip后解压到D:\some_directory\python-3.6.1-embed-amd64
2) cd python-3.6.1-embed-amd64
3) python get-pip.py
4) python -mpip 安装覆盖
5) python-3.6.1-embed-amd64\python36._pth 改为
python36.zip
Lib\site-packages
.
# Uncomment to run site.main() automatically
#import site
6) 如果要使用 Internet 代理,请使用以下命令
SET HTTP_PROXY=http://username:password@proxy_ip:proxy_port
7) python -mpip 安装覆盖
创建测试文件如下
文件module_prog.py如下
# -*- coding: utf-8 -*-
"""
Dummy method for testing
"""
def method_to_tested() -> None:
"""
Method To be tested
"""
print("Called method to be tested")
文件 test_module.py 如下
""" Unit test script for testing File : test_module.py
"""
import unittest
from module_prog import method_to_tested
class TestMethods(unittest.TestCase):
""" Testing the methods """
def test_method_to_tested(self):
method_to_tested()
if __name__ == "__main__":
unittest.main(warnings='ignore')
8)我运行以下
D:\some_directory\python-3.6.1-embed-amd64>python test_module.py
Called method to be tested
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
9) 但是,如果我使用 converage 运行下面提到的指令,我会收到以下错误。
D:\some_directory\python-3.6.1-embed-amd64>python -mcoverage run test_module.py
Traceback (most recent call last):
File "test_module.py", line 4, in <module>
import unittest
ModuleNotFoundError: No module named 'unittest'
如果我运行命令
Scripts\converage.exe run test_module.py
然后覆盖成功运行,但是如果我将嵌入式 python 移动到另一个目录并尝试运行与上面相同的命令,则会出现以下错误
D:\some_other_directory\python-3.6.1-embed-amd64>Scripts\coverage.exe run test_module.py
Fatal error in launcher: Unable to create process using
'"d:\some_directory\python-3.6.1-embed-amd64\python.exe" "D:\some_other_directory\python-3.6.1-embed-amd64\Scripts\coverage.exe" run test_module.py'
如何使覆盖作为 python 模块运行
解决方案
推荐阅读
- java - 简单的多边形点测试,边缘行为一致
- jenkins - 多分支管道插件中的“来自 SCM 的管道脚本”选项
- maven-3 - 有没有办法在 Maven 原型中订购属性?
- mysql - 用于存储问卷和多项选择答案的数据库模式
- c# - Visual Studio 应用程序以代码 -1 (0xffffffff) 退出,应用程序没有响应
- c# - Number is notcoming is DropDownlist using loop
- python - Python Pywin32 - ReadEventLog 溢出错误
- javascript - Angular 6 中的 CSS 间距问题
- php - 使用 PHP 将时间戳插入 MySQL
- sql - 优化执行缓慢的每组最大 n 个查询