简体   繁体   中英

ImportError: No module named Binary with pytest

在此处输入图片说明

I'm working through http://blog.thedigitalcatonline.com/blog/2015/05/13/python-oop-tdd-example-part1/#.Vw0NojFJJ9n .

When I try:

$ py.test
============================= test session starts =============================
platform win32 -- Python 3.2.5, pytest-2.9.1, py-1.4.31, pluggy-0.3.1
rootdir: C:\envs\r3\binary, inifile:
plugins: capturelog-0.7
collected 0 items / 1 errors 

=================================== ERRORS ====================================
____________________ ERROR collecting tests/test_binary.py ____________________
tests\test_binary.py:3: in <module>
    import Binary
E   ImportError: No module named Binary
================= 1 pytest-warnings, 1 error in 0.20 seconds ==================

What am I doing wrong?

Add current directory to PYTHONPATH environmental variable.

As you are on Windows:

$ set PYTHONPATH="."

This shall help py.test to find and import the module.

Checking the py.test tutorial I see, that at "Writing the class" section they use exactly the same trick.

In practice, you do not have to do this, as you usually test against installed Python module (typically with setup.py in project root directory and using develop mode), and it is accessible for import easily without playing with PYTHONPATH .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM