推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
yujianwjj
V2EX  ›  Python

请教:如何运行 Python 单元测试文件

  •  
  •   yujianwjj · Aug 14, 2017 · 3429 views
    This topic created in 3391 days ago, the information mentioned may be changed or developed.

    项目结构如下:

    ├── app
    │   ├── __init__.py
    │   └── utils.py
    ├── tests
    │   ├── test_app.py
    

    app/utils的内容如下:

    class A:
    	pass
    

    以tests/test_app内容如下:

    from app.utils import A
    def test_app():
    	pass
    

    直接运行py.test tests/test_app.py,会报找不到 app 这个模块,请问需要怎么修改,才能运行 tests 下面的测试。

    7 replies  •  2017-08-14 19:25:34 +08:00
    pekingzcc
    pekingzcc
    Aug 14, 2017
    1
    lz 可以去搜一下 python 包管理 相对路径 绝对路径 ,搜完之后看看能不能解决~
    lukic
    lukic
    Aug 14, 2017
    2
    app 的 父目录里运行 `python -m unittest tests.test_app`
    messense
    messense
    Aug 14, 2017
    3
    PYTHONPATH=. pytest tests/test_app.py
    cloudyplain
    cloudyplain
    Aug 14, 2017
    4
    py.test
    BiggerLonger
    BiggerLonger
    Aug 14, 2017
    5
    直接上 nose
    guyskk
    guyskk
    Aug 14, 2017❤️1
    6
    yujianwjj
    yujianwjj
    OP
    Aug 14, 2017
    7
    @guyskk 感谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4339 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 126ms · UTC 08:11 · PVG 16:11 · LAX 00:11 · JFK 03:11
    ♥ Do have faith in what you're doing.