I have unit tested my modules using pytest without issue. I would also like to test my script (which imports some of the modules), but I am getting a permission error. I am new to writing larger python projects that actually need to be tested and maintained, so my directory structure may be non-optimal, so please let me know if that is the case. My directory structure looks like -
parent
modules
__init__.py
module1.py
...
test
...
test_script.py
script.py
My test code:
import os
import subprocess
import train
def test_train_dataset1():
#run the script
p = subprocess.Popen(['./train.py', 'test_models', 'test1', 'data/temp.json', '--isfile'])
#more code to check output
My error:
PermissionError: [Errno 13] Permission denied: './train.py'
Permission denied: './train.py'
is most certainly mean the file is not executable. To fix:
chmod a+x ./train.py
Also verify it has a proper shebang line ( #!/usr/bin/python
or such).
PS. When you do import train
do you import from the same train.py
? If not — you shouldn't give the script the same name as a module/package you're gonna import.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.