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

后端 未结 7 766
北恋
北恋 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:34

    Create a helpers package in tests folder:

    tests/
        helpers/
          __init__.py
          utils.py
          ...
        # make sure no __init__.py in here!
    setup.cfg
    

    in setup.cfg:

    [pytest]
    norecursedirs=tests/helpers
    

    the helpers will be available with import helpers.

提交回复
热议问题