[Tutor] Why does os.path.realpath('test_main.py') give different results for unittest than for testing statement in interpreter?

boB Stepp robertvstepp at gmail.com
Sun Jan 7 01:49:59 EST 2018


Win7, Python 3.6.2

If I run a unit test with the following embedded:

print('realpath =', os.path.realpath('test_main.py'))

I get the following in my test output (Only relevant line is shown):

Ensure expected list of string integers is returned. ... realpath =
c:\Projects\solitaire_scorekeeper\test_main.py

In actuality "test_main.py" is located at
"c:\Projects\solitaire_scorekeeper\tests\test_main.py"

If I open the interpreter from the directory
"c:\Projects\solitaire_scorekeeper\tests\" I get what I expect:

py3: import os.path
py3: os.path.realpath('test_main.py')
'c:\\Projects\\solitaire_scorekeeper\\tests\\test_main.py'

Would someone enlighten me as to why the different results?

TIA!

-- 
boB


More information about the Tutor mailing list