-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pytest | ||
import subprocess | ||
import glob | ||
import os | ||
|
||
root_directory = "examples/python" | ||
|
||
def test_example(example_basename): | ||
example_file = os.path.join(root_directory, example_basename) | ||
pipe = subprocess.Popen([example_file], stdout=open("/dev/null", "w"), stderr=open("/dev/null", "w")) | ||
try: | ||
pipe.wait(0.5) | ||
assert pipe.poll() == 0 | ||
except subprocess.TimeoutExpired: | ||
#-------------------------------------------------------------------------------- | ||
# Process ran OK | ||
#-------------------------------------------------------------------------------- | ||
pipe.kill() | ||
|
||
def pytest_generate_tests(metafunc): | ||
root_directory = "examples/python" | ||
example_files = glob.glob(os.path.join(root_directory, "*.py")) | ||
if len(example_files) == 0: | ||
raise RuntimeError("Couldn't find any examples in directory: %s" % root_directory) | ||
|
||
example_basenames = [os.path.basename(file) for file in example_files] | ||
metafunc.parametrize("example_basename", example_basenames) | ||
|