https://kedro.org/ logo
#questions
Title
# questions
j

Julian Nowak

03/20/2024, 3:26 PM
Hi, I'm wondering about the structure of the project. According to https://docs.kedro.org/en/stable/development/automated_testing.html#set-up-automated-testing-with-pytest the test folder should be under /src. However, in the starter example (https://github.com/kedro-org/kedro-starters/tree/main/spaceflights-pandas/%7B%7B%20cookiecutter.repo_name%20%7D%7D (and while running
kedro new --name=<your-project-name> --example=yes
) it's created separately on the same level as /src. Is this a bug or a feature?
btw I'm really waiting for https://github.com/kedro-org/kedro/issues/1271, could the internal docs become public some day?
d

Deepyaman Datta

03/20/2024, 3:28 PM
I believe test should be outside
src
, and this is a known issue that needs to be updated.
👍 1
> btw I'm really waiting for https://github.com/kedro-org/kedro/issues/1271, could the internal docs become public some day? > This issue is being worked on now!
❤️ 1
j

Julian Nowak

03/20/2024, 3:30 PM
Thanks! Is there a discussion where I could learn more on why it should be kept seperate?
d

Deepyaman Datta

03/20/2024, 3:31 PM
Let me find a link; in short, purpose or src layout is to isolate code from other things.
n

Nok Lam Chan

03/20/2024, 3:42 PM
@Julian Nowak Would you mind leave a comment on the issue itself? It helps a lot for our priority.
though I know that it's WIP and there are tickets this sprint for extracting that internal document to the public documentation, stay tuned :) Cc @Ahdra Merali
j

Julian Nowak

03/20/2024, 3:51 PM
@Nok Lam Chan sure, on this one: https://github.com/kedro-org/kedro/issues/1271
?
👍🏼 1
Added! And where I could raise the issue of inconsistency between docs and the sample project structure?
thankyou 1
n

Nok Lam Chan

03/20/2024, 3:53 PM
that issue exist already
d

Deepyaman Datta

03/20/2024, 4:00 PM
j

Julian Nowak

03/20/2024, 4:03 PM
I have a question then, my custom dataset that I created imports some function from:
Copy code
from {project}.pipelines.common_methods import _to_numeric
when I reference the dataset in its test:
Copy code
from src.{project}.datasets.my_dataset import MyDataset
(now I have to add this
src.
, right?) and run
pytest
I get the error
Copy code
src\{project}\datasets\MyDataset.py:13: in <module>
    from {project}.pipelines.common_methods import _to_numeric
E   ModuleNotFoundError: No module named '{project}'
Should I add my project to pytonpath in some other way that it is done by default?
d

Deepyaman Datta

03/20/2024, 4:04 PM
Yeah, you shouldn't import
from src
https://stackoverflow.com/a/50156706 this is a nice solution; actually wasn't aware of it previously, but should work
j

Julian Nowak

03/20/2024, 4:10 PM
The first method didn't work for me, but installing it with
pip install .
does
t

Takieddine Kadiri

03/20/2024, 4:15 PM
I suggest you to install your project in editable mode:
pip install -e .
👍 2
j

Julian Nowak

03/20/2024, 4:16 PM
@Takieddine Kadiri thanks!
👍 1
t

Takieddine Kadiri

03/20/2024, 4:24 PM
By going into the
pip install
approach you're not relying on kedro nor on pytest for adding your packages that live under
src
to the sys path, you could then import your package from whatever module that live inside your python env. You're however relying on Kedro's template that preconfigure the
pyproject.toml
to play well with the src layout.
j

Julian Nowak

03/20/2024, 4:27 PM
I hope best practices for this will be included in the documentation as well 😄