sys.path contiene las rutas donde python irá a buscar los módulos que importes con import.
Por lo general no es común que uses el sys.path, el mismo sistema de encarga de ubicar los módulos que se importan y que se encuentran dentro del árbol de directorios de tu proyecto con tan sólo añadir un archivo llamado __init__.py dentro de cada directorio.
al tu añadir el directorio .. a tu ruta este buscará también los módulos un directorio atrás de donde tu programa se esté ejecutando actualmente, no con respecto al archivo .py.
Por ejemplo:
import os
import sys
sys.path.append('..')
print(os.listdir(sys.path[-1]))
$ pwd
/home/alex/proyectos/python/tests
$ python3 test1.py
['tests', 'ANU', 'hashtables_tests']
$ cd ..
$ python3 tests/test1.py
['wimdAPI', 'MicrochipData', 'RaspberryPi', 'arm_ide', 'au', '.gitignore', 'Cordova', 'MSP340', 'Electron', 'nodejs', 'repuve', 'Pomodoro', 'cloud', 'python', 'RecyBot', 'electron', 'libs', 'microcontrollers', 'wave', 'RealTime', 'mosquitto', 'MonitorS', '.git', '8051', 'ghdl', 'games', 'TestM', 'Ada', 'OpenERP', 'Odoo', 'esp8266', 'ARMIDE', 'PCBExample', 'VHDL', 'BMLP', 'TivaC', 'FacturaSAT']
Como puedes observar, no es realmente útil para fines prácticos agregar sólo el ..
Probablemente lo que quieres hacer es añadir al sys.path un directorio que se encuentra por encima de tu archivo .py
Para ello puedes obtener la ruta de tu actual archivo, y con respecto a esa ruta añadir el .. a tu sys.path
import os
import sys
#sys.path.append('..')
#print(os.listdir(sys.path[-1]))
#print(sys.path[-1])
print(__file__)
print(os.path.abspath(__file__))
$ python3 tests/test1.py
tests/test1.py
$ cd tests
$ python3 test1.py
test1.py
/home/alex/proyectos/python/tests/test1.py
Y extraemos sólo le nombre del directorio donde el archivo test1.py se encuentra
import os
import sys
#sys.path.append('..')
#print(os.listdir(sys.path[-1]))
#print(sys.path[-1])
print(__file__)
print(os.path.abspath(__file__))
print(os.path.dirname(os.path.abspath(__file__))
$ python3 test1.py
test1.py
/home/alex/proyectos/python/tests/test1.py
/home/alex/proyectos/python/tests
$ cd ..
$ python3 tests/test1.py
tests/test1.py
/home/alex/proyectos/python/tests/test1.py
/home/alex/proyectos/python/tests
¿Cómo añades a tu sys.path .. con respecto al directorio de tu archivo .py?
import os
import sys
file_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(file_dir,'..'))
print(sys.path[-1])
print(os.listdir(sys.path[-1]))
No importa desde que directorio se ejecute o sea llamado tu archivo .py, siempre vas a obtener el mismo resultado
$ python3 tests/test1.py
/home/alex/proyectos/python/tests/..
['tests', 'ANU', 'hashtables_tests']
$ cd tests
$ python3 test1.py
/home/alex/proyectos/python/tests/..
['tests', 'ANU', 'hashtables_tests']
¿Porqué es mejor usar os.path.join?, porque Windows y Linux no manejan las rutas de la misma forma. Lo podrías hacer con file_dir+”/..”, pero no sería portable.