Question
How can I import helper functions in test files without creating packages in the test
directory?
Context
I'd like to create a test helper function that I can import in several tests. Say, something like this:
# In common_file.py
def assert_a_general_property_between(x, y):
# test a specific relationship between x and y
assert ...
# In test/my_test.py
def test_something_with(x):
some_value = some_function_of_(x)
assert_a_general_property_between(x, some_value)
Using Python 3.5, with py.test 2.8.2
Current "solution"
I'm currently doing this via importing a module inside my project's test
directory (which is now a package), but I'd like to do it with some other mechanism if possible (so that my test
directory doesn't have packages but just tests, and the tests can be run on an installed version of the package, as is recommended here in the py.test documentation on good practices).
__init__.py
-files but at the same time provide no alternative to sharing helper functions between tests. My hair is turning gray over this.short test summary info
when I import a plain, sister, file, sayhelpers
containing a function that fails anassert
. If the functions aren'timport
ed, I still get as helpful output as if they were inline in thetest_
function being run.