Create and import helper functions in tests without creating packages in test directory using py.test

后端 未结 7 743
北恋
北恋 2020-12-24 04:57

Question

How can I import helper functions in test files without creating packages in the test directory?


Contex

7条回答
  •  爱一瞬间的悲伤
    2020-12-24 05:25

    As another option, this directory structure worked for me:

    mypkg/
        ...
    test_helpers/
        __init__.py
        utils.py  
        ...
    tests/
        my_test.py
        ...
    

    And then in my_test.py import the utilities using: from test_helpers import utils

提交回复
热议问题