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

后端 未结 7 740
北恋
北恋 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:16

    To access a method from different modules without creating packages, and have that function operate as a helper function I found the following helpful:

    conftest.py:

    @pytest.fixture
    def compare_test_vs_actual():
        def a_function(test, actual):
            print(test, actual)
        return a_function
    

    test_file.py:

    def test_service_command_add(compare_test_vs_actual):
        compare_test_vs_actual("hello", "world")
    

提交回复
热议问题