Python 在pytest库中运行测试时发生ModuleNotFoundError
我的文件结构:Python 在pytest库中运行测试时发生ModuleNotFoundError,python,import,pytest,Python,Import,Pytest,我的文件结构: ----foo.py ----boo.py ----测试文件夹 --------------test\u foo.py --------------\uuuuu init\uuuuuuuuupy 在foo.py中,我得到了import boo。 Mytest\u foo.py包含: import sys sys.path.insert(0, 'd:\path\to\foo\and\bo') import foo pytest库似乎无法访问boo.py,我得到了ModuleNot
----foo.py
----boo.py
----测试文件夹
--------------test\u foo.py
--------------\uuuuu init\uuuuuuuuupy
在foo.py
中,我得到了import boo
。
Mytest\u foo.py
包含:
import sys
sys.path.insert(0, 'd:\path\to\foo\and\bo')
import foo
pytest库似乎无法访问boo.py
,我得到了ModuleNotFoundError:没有名为“boo”的模块
。你知道原因是什么吗
运行时:
import sys
sys.path.insert(0, 'd:\Python\Projects\gym-cards\gym_cards\envs')
print(help('modules'))
此外,foo文件中的import boo
会导致Pycharm发出警告,好像它没有看到它一样。这很奇怪,因为一切都很好。这里应该列出boo吗
IPython binascii jupyter scipy
PIL binhex jupyter_client secrets
PyQt5 bisect jupyter_console select
TBB bleach jupyter_core selectors
__future__ builtins keyword setup
_ast bz2 kiwisolver setuptools
_asyncio cProfile lib2to3 shelve
_bisect caffe2 libfuturize shlex
_blake2 calendar libpasteurize shutil
_bootlocale cards_env linecache signal
_bz2 certifi locale simplegeneric
_cffi_backend cffi logging sip
_codecs cgi lzma sipconfig
_codecs_cn cgitb macpath sipdistutils
_codecs_hk chardet macurl2path site
_codecs_iso2022 chunk mailbox sitecustomize
_codecs_jp cmath mailcap six
_codecs_kr cmd markupsafe smtpd
_codecs_tw code marshal smtplib
_collections codecs math sndhdr
_collections_abc codeop matplotlib socket
_compat_pickle collections mimetypes socketserver
_compression colorama mistune sqlite3
_csv colorsys mkl_fft sre_compile
_ctypes compileall mkl_random sre_constants
_ctypes_test concurrent mmap sre_parse
_datetime configparser model ssl
_decimal contextlib modulefinder stat
_distutils_findvs copy more_itertools statistics
_dummy_thread copyreg msilib storemagic
_elementtree crypt msvcrt string
_functools csv multiprocessing stringprep
_hashlib ctypes nbconvert struct
_heapq curses nbformat subprocess
_imp cycler netrc sunau
_io cythonmagic nntplib symbol
_json datetime notebook sympyprinting
_locale dateutil nt symtable
_lsprof dbm ntpath sys
_lzma decimal nturl2path sysconfig
_markupbase decorator numbers tabnanny
_md5 difflib numexpr tarfile
_msi dill numpy tbb
_multibytecodec dis olefile telnetlib
_multiprocessing distutils opcode tempfile
_opcode doctest operator test
_operator dqn_agent optparse test_cards_env
_osx_support dummy_threading os test_path
_overlapped easy_install pandas testpath
_pickle easyprocess pandocfilters tests
_pydecimal email parser textwrap
_pyio encodings parso this
_pytest ensurepip past threading
_random entrypoints path time
_sha1 enum pathlib timeit
_sha256 environment_tests pdb tkinter
_sha3 errno pickle token
_sha512 evca pickleshare tokenize
_signal faulthandler pickletools torch
_sitebuiltins filecmp pip torchvision
_socket fileinput pipes tornado
_sqlite3 fnmatch pkg_resources trace
_sre formatter pkgutil traceback
_ssl fractions platform tracemalloc
_stat ftplib plistlib training
_string functools pluggy traitlets
_strptime future poplib tty
_struct gc posixpath turtle
_symtable genericpath pprint turtledemo
_testbuffer getopt profile types
_testcapi getpass prompt_toolkit typing
_testconsole gettext pstats unicodedata
_testimportmultiple glob pty unittest
_testmultiphase gym py urllib
_thread gym_cards py_compile urllib3
_threading_local gzip pyclbr uu
_tkinter hashlib pycparser uuid
_tracemalloc heapq pydoc venv
_warnings hmac pydoc_data warnings
_weakref html pyexpat wave
_weakrefset html5lib pygame wcwidth
_winapi http pyglet weakref
abc idlelib pygments webbrowser
aifc idna pylab webencodings
antigravity imaplib pyparsing wheel
argparse imghdr pyreadline widgetsnbextension
array imp pytest win_unicode_console
ast importlib pytz wincertstore
asynchat inspect pyvirtualdisplay winreg
asyncio io queue winsound
asyncore ipaddress quopri wsgiref
atexit ipykernel random xdrlib
atomicwrites ipykernel_launcher re xml
attr ipython_genutils readline xmlrpc
audioop ipywidgets reprlib xxsubtype
autoreload itertools requests zipapp
backcall jedi rlcompleter zipfile
backend_interagg jinja2 rmagic zipimport
backports json run zlib
base64 jsonpickle runpy zmq
bdb jsonschema sched
运行
help(“modules”)
查看什么是可加载的。我应该在哪里运行它?在python控制台中。只要运行python
@richanderws,@AnthonyKong-我发现在列出所有模块之前也有一个错误。它是D:\Python\Anaconda3\envs\python36\lib\site packages\zmq\backend\cffi\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ cffi ext.c(213):致命错误C1083:无法打开文件,添加'sys/un.h':没有这样的文件或目录
运行帮助(“模块”)
。只要运行python
@richanderws,@AnthonyKong-我发现在列出所有模块之前也有一个错误。它是D:\Python\Anaconda3\envs\python36\lib\site packages\zmq\backend\cffi\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\