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

Albert-Jan Roskam sjeik_appie at hotmail.com
Sun Jan 7 05:51:20 EST 2018


On Jan 7, 2018 09:08, Steven D'Aprano <steve at pearwood.info> wrote:
>
> On Sun, Jan 07, 2018 at 12:49:59AM -0600, boB Stepp wrote:
>
> > 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
>
>
> realpath() returns the canonical path of the given filename. It doesn't
> try to locate some actual existing file.

I always thought that os.path.realpath is the Python equivalent of Linux realpath/readlink (http://man7.org/linux/man-pages/man3/realpath.3.html). And that, thus, there's only a difference between input and output when the input is a symlink (and maybe also when it's a hard link - in this case the function actually also does something in Windows). But then, I don't really know the meaning of the word "canonical", to tell you the truth (maybe #4 in http://www.dictionary.com/browse/canonical)


More information about the Tutor mailing list