Note that there are some explanatory texts on larger screens.

plurals
  1. POboilerplateless tests
    primarykey
    data
    text
    <p>I have testing files wirtten in Python : test1.py test2.py... Before executing any of them I need to initialize them with a file called initialize.py that takes arguments.</p> <p>The testing files must stay as light and easy to write as they can be.</p> <p>I want to create a script that:</p> <ol> <li>Takes input arguments</li> <li>Start the initialize.py file with those arguments</li> <li>Start the test file using the variables created by initialize.py</li> </ol> <p>I thought about a few ways:</p> <ul> <li>Import the two files : it doesn't work because with import you can use the return argument on your main script but you can't give input argument</li> <li>Transform both files into functions : it's not an issue with initialize.py but as I said I want to keep the test file to be as easy and light as possible so if I can avoid that it's better.</li> <li>The perfect solution would be to simply "copy" the code from initialize and put it in the beggining of the test file (or the opposite). May be create a temporary file containing both code but i don't think it very clean.</li> </ul> <p>To sum up : it's as if I had 100 files that starts with the same 25 lines and I want to put those 25 lines in one file and import them each time.</p> <p>An other way to see things is 3 files:</p> <pre><code>#File1.py var1 = sys.argv(1) #File2.py var2 = var1+"second" #File3.py var3 = var1+var2+"third" print var3 </code></pre> <p>I want to start ./File1.py first And get "first second thrid"</p> <p>I succeed with</p> <pre><code>#! /usr/bin/python import sys import subprocess source_content = "#! /usr/bin/python\n"+"import sys\n" sourcefile = "file2.py" txt_file = open(sourcefile) source_content += txt_file.read() sourcefile = "file3.py" txt_file = open(sourcefile) source_content += txt_file.read() destinationfile = "Copyfile2.py" target = open (destinationfile, 'w') target.write(source_content) target.close() chmodFile = "chmod 777 "+destinationfile chmod = subprocess.Popen(chmodFile, shell=True) chmod.wait() arguments = str("./"+destinationfile+" ") arguments += " ".join(map(str,sys.argv[1:len(sys.argv)])) startTest = subprocess.Popen(arguments, shell=True) startTest.wait() </code></pre> <p>But I had to delete the "#! /usr/bin/python" from test2 and test and rename var1 to sys.arg[1] on thoses same files. And I don't think it's a nice solution...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload