在pytest库中运行测试时出现ModuleNotFoundError

时间:2019-03-18 23:28:26

标签: python import pytest

我的文件结构:

----foo.py

----boo.py

----tests_folder

-----------------test_foo.py

-----------------__init__.py

foo.py中,我有import boo。 我的test_foo.py包含:

import sys
sys.path.insert(0, 'd:\path\to\foo\and\bo')
import foo

似乎pytest库无法访问boo.py,而我得到ModuleNotFoundError: No module named 'boo'。任何想法可能是什么原因?

运行时:

import sys
sys.path.insert(0, 'd:\Python\Projects\gym-cards\gym_cards\envs')
print(help('modules'))

foo文件中的import boo也导致Pycharm发出警告,因为它没有看到警告。这很奇怪,因为一切正常。这里应该列出嘘吗?

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          

0 个答案:

没有答案
相关问题