pycharm2016.2.X中出现“Parent module ‘YOUR_MODULE_HERE’ not found while handling absolute import ”解决方法
来源:互联网 发布:残疾人婚恋软件 编辑:程序博客网 时间:2024/05/27 10:43
调试环境:
系统:window7 64
软件:pycharm
版本:2016.2.3
在使用本版本的pycharm时,进行unittest的时候,出现如下提示的错误提示:
RuntimeWarning: Parent module ‘YOUR_MODULE_HERE’ not found while handling absolute import
其实这是pycharm2016.2.X的一个Bug,在pycharm2017中已经修复。如何继续在pycharm2016.2.X正常试用呢??
解决方法:
使用旧的utrunner.py文件替换当前版本,文件路径为…/PyCharm.app/Contents/helpers/pycharm/utrunner.py(macos平台)
或者…\JetBrains\PyCharm 2016.2.2\helpers\pycharm\utrunner.py(windows平台)
utrunner.py的内容如下(替换文件前请先做好备份):
import sysimport impimport osimport fnmatchhelpers_dir = os.getenv("PYCHARM_HELPERS_DIR", sys.path[0])if sys.path[0] != helpers_dir: sys.path.insert(0, helpers_dir)from tcunittest import TeamcityTestRunnerfrom nose_helper import TestLoader, ContextSuitefrom pycharm_run_utils import import_system_modulefrom pycharm_run_utils import adjust_sys_pathfrom pycharm_run_utils import debug, getModuleName, PYTHON_VERSION_MAJORadjust_sys_path()os = import_system_module("os")re = import_system_module("re")modules = {}def loadSource(fileName): baseName = os.path.basename(fileName) moduleName = os.path.splitext(baseName)[0] # for users wanted to run unittests under django #because of django took advantage of module name settings_file = os.getenv('DJANGO_SETTINGS_MODULE') if settings_file and moduleName == "models": baseName = os.path.realpath(fileName) moduleName = ".".join((baseName.split(os.sep)[-2], "models")) if moduleName in modules and len(sys.argv[1:-1]) == 1: # add unique number to prevent name collisions cnt = 2 prefix = moduleName while getModuleName(prefix, cnt) in modules: cnt += 1 moduleName = getModuleName(prefix, cnt) debug("/ Loading " + fileName + " as " + moduleName) if os.path.isdir(fileName): fileName = fileName + os.path.sep module = imp.load_source(moduleName, fileName) modules[moduleName] = module return moduledef walkModules(modulesAndPattern, dirname, names): modules = modulesAndPattern[0] pattern = modulesAndPattern[1] # fnmatch converts glob to regexp prog_list = [re.compile(fnmatch.translate(pat.strip())) for pat in pattern.split(',')] for name in names: for prog in prog_list: if name.endswith(".py") and prog.match(name): modules.append(loadSource(os.path.join(dirname, name)))# For default pattern see https://docs.python.org/2/library/unittest.html#test-discoverydef loadModulesFromFolderRec(folder, pattern="test*.py"): modules = [] # fnmatch converts glob to regexp prog_list = [re.compile(fnmatch.translate(pat.strip())) for pat in pattern.split(',')] for root, dirs, files in os.walk(folder): files = [f for f in files if not f[0] == '.'] dirs[:] = [d for d in dirs if not d[0] == '.'] for name in files: for prog in prog_list: if name.endswith(".py") and prog.match(name): modules.append(loadSource(os.path.join(root, name))) return modulestestLoader = TestLoader()all = ContextSuite()pure_unittest = Falsedef setLoader(module): global testLoader, all try: module.__getattribute__('unittest2') import unittest2 testLoader = unittest2.TestLoader() all = unittest2.TestSuite() except: passif __name__ == "__main__": arg = sys.argv[-1] if arg == "true": import unittest testLoader = unittest.TestLoader() all = unittest.TestSuite() pure_unittest = True if len(sys.argv) == 2: # If folder not provided, we need pretend folder is current sys.argv.insert(1, ".") options = {} for arg in sys.argv[1:-1]: arg = arg.strip() if len(arg) == 0: continue if arg.startswith("--"): options[arg[2:]] = True continue a = arg.split("::") if len(a) == 1: # From module or folder a_splitted = a[0].split("_args_separator_") # ";" can't be used with bash, so we use "_args_separator_" if len(a_splitted) != 1: # means we have pattern to match against if os.path.isdir(a_splitted[0]): debug("/ from folder " + a_splitted[0] + ". Use pattern: " + a_splitted[1]) modules = loadModulesFromFolderRec(a_splitted[0], a_splitted[1]) else: if os.path.isdir(a[0]): debug("/ from folder " + a[0]) modules = loadModulesFromFolderRec(a[0]) else: debug("/ from module " + a[0]) modules = [loadSource(a[0])] for module in modules: all.addTests(testLoader.loadTestsFromModule(module)) elif len(a) == 2: # From testcase debug("/ from testcase " + a[1] + " in " + a[0]) module = loadSource(a[0]) setLoader(module) if pure_unittest: all.addTests(testLoader.loadTestsFromTestCase(getattr(module, a[1]))) else: all.addTests(testLoader.loadTestsFromTestClass(getattr(module, a[1])), getattr(module, a[1])) else: # From method in class or from function debug("/ from method " + a[2] + " in testcase " + a[1] + " in " + a[0]) module = loadSource(a[0]) setLoader(module) if a[1] == "": # test function, not method all.addTest(testLoader.makeTest(getattr(module, a[2]))) else: testCaseClass = getattr(module, a[1]) try: all.addTest(testCaseClass(a[2])) except: # class is not a testcase inheritor all.addTest( testLoader.makeTest(getattr(testCaseClass, a[2]), testCaseClass)) debug("/ Loaded " + str(all.countTestCases()) + " tests") TeamcityTestRunner().run(all, **options)
也可到小编的百度网盘进行下载:
链接: https://pan.baidu.com/s/1hr4sOb6 密码: fyut
阅读全文
0 0
- pycharm2016.2.X中出现“Parent module ‘YOUR_MODULE_HERE’ not found while handling absolute import ”解决方法
- RuntimeWarning: Parent module 'settings' not found while handling absolute import
- unittest RuntimeWarning: Parent module '' not found while handling absolute import
- 解决 RuntimeWarning: Parent module '...' not found while handling absolute import
- unittest RuntimeWarning: Parent module XX not found while handling absolute import
- IIS出现The specified module could not be found解决方法
- IIS出现The specified module could not be found解决方法
- "FATAL: Module scsi_wait_scan not found" 解决方法
- IIS出现The specified module could not be found的解决方法
- IIS出现The specified module could not be found错误解决方法!
- IIS不能访问,出现The specified module could not be found问题 解决方法
- IIS出现The specified module could not be found的解决方法
- bash脚本中出现[[:not found错误的解决方法
- python3.5中,import sqlite3 出现 no module named _sqlite3的解决方法
- Pycharm2016.2.x激活方法
- Python进阶(四十八)-Python导包时提示SystemError: Parent module '' not loaded, cannot perform relative import
- Hibernate中配置文件出现class cn.fpxty.LinkMan not found while looking for property:linkid错误
- linux出现command not found的解决方法
- 支付宝电脑网站支付,也就是老版的即时到账
- 读《读库1704》
- Slave failed to initialize relay log info structure from the repository, Error_code: 1872
- Hibernate添加log4j的实现
- 【背包专题】J
- pycharm2016.2.X中出现“Parent module ‘YOUR_MODULE_HERE’ not found while handling absolute import ”解决方法
- ArrayList和Vector的区别
- java编程思想第一章 对象
- 我的第一个博客
- 域服务篇 04. 组 ❀ Windows Server 2016
- code-push-server的部署(docker)
- sqlserver 日期加减问题
- 运维知道
- [PAT]1010. Radix (25)@Java解题报告