I would like to create a test for a python 3.7+ script called foo-bar
(that's the file name, and it has no .py
extension):
#!/usr/bin/env python
def foo(bar):
return bar + 42
if __name__ == '__main__':
print(foo(1))
How can I load this file by path alone, so that I can test the foo()
method? The test should NOT trigger the if main
condition.
UPDATE note that this is not about executing
the file from the test (i.e. exec('foo-bar')
), but rather loading/importing it as a module/resource, allowing the test code to execute foo()
on it.