Created
September 2, 2013 13:15
-
-
Save bilderbuchi/6412754 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/python | |
import sys | |
with open(sys.argv[1],'r') as input_file: | |
print input_file.read() |
This file contains hidden or 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
--Contents of arg_file.txt-- |
This file contains hidden or 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
# content of tests/conftest.py | |
import pytest | |
import os, shutil | |
BASEDIR = os.path.dirname(__file__) | |
@pytest.fixture() | |
def set_up(tmpdir): | |
"""Create tmpdir, copy arg_file over""" | |
tmpdir.chdir() | |
shutil.copyfile(os.path.join(BASEDIR, 'arg_file.txt'), | |
os.path.join(os.getcwd(), 'arg_file.txt')) | |
print('\nset_up: In directory ' + os.getcwd()) |
This file contains hidden or 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
# content of tests/test_in_scriptdir.py | |
import subprocess, shlex, os | |
import pytest | |
BASEDIR = os.path.dirname(__file__) #this points to the tests/ directory | |
@pytest.mark.usefixtures('set_up') | |
class TestInScriptdir: | |
def test_1(self): | |
"""Execute script in script dir where my_script.py resides""" | |
# remember path to tmpdir | |
temporary = os.getcwd() | |
# change to script directory | |
os.chdir(os.path.join(BASEDIR,'..')) | |
print('Running in directory ' + os.getcwd()) | |
# run script | |
command = './my_script.py ' + os.path.join(temporary, 'arg_file.txt') | |
print('Command: ' + command) | |
subprocess.call(shlex.split(command), | |
stderr=subprocess.STDOUT, | |
cwd=os.getcwd()) |
This file contains hidden or 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
# content of tests/test_in_tmpdir.py | |
import subprocess, shlex, os | |
import pytest | |
BASEDIR = os.path.dirname(__file__) #this points to the tests/ directory | |
@pytest.mark.usefixtures('set_up') | |
class TestInTempdir: | |
def test_1(self): | |
"""Execute script in tmpdir where arg_file.txt resides""" | |
print('Running in directory ' + os.getcwd()) | |
# run script | |
command = os.path.abspath(os.path.join(BASEDIR, '..', 'my_script.py')) + ' arg_file.txt' | |
print('Command: ' + command) | |
output = subprocess.call(shlex.split(command), | |
stderr=subprocess.STDOUT, | |
cwd=os.getcwd()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment