首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >测试失败,因为无法找到测试中的模块

测试失败,因为无法找到测试中的模块
EN

Stack Overflow用户
提问于 2018-03-30 10:01:45
回答 1查看 2K关注 0票数 1

我的毒理有点问题。测试无法运行,因为无法找到正在测试的模块。从我所做的挖掘中,我怀疑问题可能是毒物测试用错了解释器。我在用Windows,如果有关系的话。

无法找到包,即使它已安装到venv中:

代码语言:javascript
复制
C:\Users\galli\Desktop\projects\RedditBotBuilder>tox
GLOB sdist-make: C:\Users\galli\Desktop\projects\RedditBotBuilder\setup.py
py36 inst-nodeps: C:\Users\galli\Desktop\projects\RedditBotBuilder\.tox\dist\RedditBotBuilder-1.0.0.zip
py36 installed: attrs==17.4.0,certifi==2018.1.18,chardet==3.0.4,colorama==0.3.9,idna==2.6,more-itertools==4.1.0,pluggy==0.6.0,praw==5.4.0,prawcore==0.14.0,py==1.5.3,pytest==3.5.0,RedditBotBuilder==1.0.0,requests==2.18.4,six==1.11.0,update-checker==0.16,urllib3==1.22
py36 runtests: PYTHONHASHSEED='150'
py36 runtests: commands[0] | pytest --verbose tst/
============================= test session starts =============================
platform win32 -- Python 3.6.3, pytest-3.5.0, py-1.5.3, pluggy-0.6.0 -- c:\users\galli\desktop\projects\redditbotbuilder\.tox\py36\scripts\python.exe
cachedir: .pytest_cache
rootdir: C:\Users\galli\Desktop\projects\RedditBotBuilder, inifile:
collected 0 items / 1 errors

=================================== ERRORS ====================================
_____________ ERROR collecting tst/redditbotbuilder/test_bots.py ______________
ImportError while importing test module 'C:\Users\galli\Desktop\projects\RedditBotBuilder\tst\redditbotbuilder\test_bots.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tst\redditbotbuilder\test_bots.py:3: in <module>
    from redditbotbuilder.bots import RedditBot
E   ModuleNotFoundError: No module named 'redditbotbuilder.bots'
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!
=========================== 1 error in 0.22 seconds ===========================
ERROR: InvocationError: 'C:\\Users\\galli\\Desktop\\projects\\RedditBotBuilder\\.tox\\py36\\Scripts\\pytest.EXE --verbose tst/'
______________________________________________________ summary _______________________________________________________
ERROR:   py36: commands failed

下面是目录结构,我已经将项目导入到PyCharm中,它没有抱怨就解析了模块:

代码语言:javascript
复制
src/
src/redditbotbuilder/
src/redditbotbuilder/bots.py
src/redditbotbuilder/__init__.py
tst/
tst/redditbotbuilder/
tst/redditbotbuilder/test_bots.py
tst/redditbotbuilder/__init__.py
tox.ini
setup.py

这是setup.py

代码语言:javascript
复制
setup(
    name="RedditBotBuilder",
    description="A Python framework for quickly building reddit bots",
    version="1.0.0",
    url="someUrl.com",
    author="Guy McGuyerson",
    author_email="guymcguyerson@gmail.com",
    classifiers=[
        "Programming Language :: Python",
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
        "Intended Audience :: Developers",
        "Topic :: Software Development :: Libraries :: Python Modules"
    ],
    packages=find_packages("src"),
    package_dir={'': 'src'},
    install_requires=["praw"]
)

这是tox.ini

代码语言:javascript
复制
[tox]
envlist = py36

[testenv]
deps=pytest
commands=pytest --verbose tst/

RedditBotBuilder已安装在venv中:

代码语言:javascript
复制
(py36) C:\Users\galli\Desktop\projects\RedditBotBuilder\.tox\py36\Scripts>pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
attrs (17.4.0)
certifi (2018.1.18)
chardet (3.0.4)
colorama (0.3.9)
idna (2.6)
more-itertools (4.1.0)
pip (9.0.3)
pluggy (0.6.0)
praw (5.4.0)
prawcore (0.14.0)
py (1.5.3)
pytest (3.5.0)
RedditBotBuilder (1.0.0) <----------
requests (2.18.4)
setuptools (39.0.1)
six (1.11.0)
update-checker (0.16)
urllib3 (1.22)
wheel (0.30.0)

我以为可能用错了翻译.

代码语言:javascript
复制
(py36) C:\Users\galli\Desktop\projects\RedditBotBuilder\.tox\py36\Scripts>where python
C:\Users\galli\Desktop\projects\RedditBotBuilder\.tox\py36\Scripts\python.exe
C:\Users\galli\AppData\Local\Programs\Python\Python36-32\python.exe

...but将语句import sys; print(sys.executable)添加到测试文件后,它打印C:\Users\galli\Desktop\projects\RedditBotBuilder\.tox\py36\Scripts\python.exe

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-31 23:21:12

对,我终于发现了问题。测试模块似乎正在隐藏被测试模块的名称。如果我将测试模块名更改为"notredditbotbuilder",一切都会正常工作。我不知道为什么PyCharm没有强调这个问题,但我不想花更多的时间在这个问题上。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49572339

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档