У меня проблемы с токсикоманией. Тесты не запускаются, потому что тестируемый модуль не может быть найден. Судя по проведенным мною раскопкам, я подозреваю, что проблема может заключаться в том, что tox запускает тесты с неправильным интерпретатором. Я использую Windows, если это уместно.
Не могу найти пакет, хотя он был установлен в venv:
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, и он разрешает модуль без жалоб:
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
:
setup(
name="RedditBotBuilder",
description="A Python framework for quickly building reddit bots",
version="1.0.0",
url="someUrl.com",
author="Guy McGuyerson",
author_email="[email protected]",
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
:
[tox]
envlist = py36
[testenv]
deps=pytest
commands=pytest --verbose tst/
RedditBotBuilder установлен в venv:
(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)
Я подумал, что может быть использован не тот интерпретатор ...
(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
... но после добавления оператора import sys; print(sys.executable)
в тестовый файл он напечатал C:\Users\galli\Desktop\projects\RedditBotBuilder\.tox\py36\Scripts\python.exe
.
setup.py
файл? - person John Szakmeister   schedule 30.03.2018redditbotbuilder.bots
должно бытьsrc/redditbotbuilder/__init__.py
. Это там? - person phd   schedule 30.03.2018src/redditbotbuilder/__init__.py
, иtst/redditbotbuilder/__init__.py
существуют. Я отправлюsetup.py
, когда у меня будет доступ к моему домашнему компьютеру (может быть, через пару часов), спасибо за помощь. - person Pig   schedule 30.03.2018setup.py
в сообщение. - person Pig   schedule 30.03.2018activate.bat; python
) и импортировать модуль из него! - person Pig   schedule 30.03.2018