[Tutor] file accessibility across directories?
dn
PythonList at DancesWithMice.info
Wed Feb 28 20:45:00 EST 2024
On 29/02/24 13:06, Mats Wichmann wrote:
> On 2/28/24 15:39, James Hartley wrote:
>> While in the project directory:
>> $ pwd
>> /home/me/project
>> $ cat src/foo.py
>> class Foo:
>> pass
>> $ cat utils/baz.py
>> from src.foo import Foo
>> $ python utils/baz.py
>> Traceback (most recent call last):
>> File "./baz.py", line 1 in <module>
>> from src.foo import Foo
>> ModuleNotFoundError: No module named 'src'
>
>
> When you run a script, the directory of the script is added to sys.path.
> Not the directory you were in when you ran it. You can print out
> sys.path in utils/baz.py to convince yourself of this. There's no src
> in that directory (utils).
Whereas pytest works the other way around: run from the
project-directory because its (internal) 'process of discovery' will
find test* files by searching the entire directory-tree...
(hence the questions in earlier reply)
--
Regards,
=dn
More information about the Tutor
mailing list