Importing correctly with pytest

前端 未结 4 1870
野趣味
野趣味 2020-12-13 23:25

I just got set up to use pytest with Python 2.6. It has worked well so far with the exception of handling \"import\" statements: I can\'t seem to get pytest to respond to im

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-13 23:45

    If you include an __init__.py file inside your tests directory, then when the program is looking to set a home directory it will walk 'upwards' until it finds one that does not contain an init file. In this case src/.

    From here you can import by saying :

    from geom.region import *
    

    you must also make sure that you have an init file in any other subdirectories, such as the other nested test directory

提交回复
热议问题