Open mjallday opened 10 years ago
I've run into this problem with the examples before. I'll have a look at it. Any suggestions on how the examples could be run as part of the test suite?
We can either enumerate all the files in the directory and run them then check for return code == 0 or rewrite the examples to be importable (e.g. if __name__ == 'main': run_example()
).
I think the first is probably less work so doing it that way would be easier.
On the test side I think something like
import subprocess, sys
class ExampleTests(TestCase):
def test_examples_run(self):
for example_file_name in example_dir_files:
self.assertEqual(subprocess.call( sys.executeable + " " + example_file_name, shell=True), 0)
this is probably a pretty naive implementation but it has the general idea right.
hat tip to @coderanger for the sys.executable
move.
It's too easy to break the examples and not know about it.