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

Artur Dobrogowski

03/26/2024, 10:51 PM
Pytest in kedro starters - when you make new project with
kedro new
in 0.19.3 or use for example
spaceflights-pandas
- is it only me or those tests need more love? 1. running
pytest
in root dir or in tests dir does not work - it's not properly configured to find your main module. I needed to move tests dir to
src/
to make it work or edit
pyproject.toml
2. spaceflights-pandas still uses ConfigLoader which was removed and throws error.
kedro new
has OmegaConfig there and it works, but... 3. even then in both cases I get another error: E TypeError: KedroContext.__init__() missing 1 required positional argument: 'env' /home/adobrogo/projects/kedro/jupyter-lab/template-test/tests/test_run.py26 TypeError
Looks like passing tests in official starters could be added to your cicd so you catch the errors earlier šŸ™‚
Didn't check on github if there's already issue for that - there could be
n

Nok Lam Chan

03/26/2024, 11:08 PM
Hey @Artur Dobrogowski, thanks for reporting this. Indeed we are spending some time on tests this week: 1. is being fixed already and we have it tracked in Github for a while. 2. do you also mean test? If so I believe it is fixed too (not release yet) 3. We are also adding some documentation for testing with Kedro project Meanwhile we have some discussion about the development of a testing module Kedro, which helps users to create test for the project.
Not qutie sure what is the error you mentioned. maybe a snippet?
a

Artur Dobrogowski

03/26/2024, 11:12 PM
2. yes
n

Nok Lam Chan

03/26/2024, 11:12 PM
https://github.com/kedro-org/kedro-starters/blob/main/spaceflights-pandas/%7B%7B%20cookiecutter.repo_name%20%7D%7D/tests/test_run.py this is the latest template, though some of them still looks incorrect to me, do you want to send a PR to fix this?
a

Artur Dobrogowski

03/26/2024, 11:12 PM
3. another error with kedroContext missing env
return KedroContext(
is missing
env="local",
for example
not sure if this is the only issue, but fixing that got it running - we need to review all other starters
could do PR but I have time for that on friday
actually I maybe can do it now, but I can't figure out why in some projects it has no issue finding the main module to import while being outside
src/
while in others it can't
maybe poetry does some magic behind the scenes
Yes turned out to be poetry
So we have 3 options according to https://docs.pytest.org/en/7.1.x/explanation/goodpractices.html?highlight=src#tests-outside-application-code : ā€¢ add to documentation instruction to add your package in editable mode
pip install . -e
---> poetry does that for you by default so that's why it was working in my other poetry setup ā€¢ add instruction that you can run it by going to
src/
and then leveraging
python -m pytest ../tests
(and /or add
tests
to tests path in
pyproject.toml
) ā€¢ move
tests
dir to
src/tests
- that's what kedro docs page already assumes it to be - see https://docs.kedro.org/en/stable/development/automated_testing.html#run-your-tests So I'd vote for 3rd option, as it requires the least knowledge about
pytest
mechanisms, but improving docs is also a must. What do you think @Nok Lam Chan?
n

Nok Lam Chan

03/26/2024, 11:43 PM
@Yury Fedotov is working on 1. IIRC. This is a good practice but not strictly required by Kedro.
I disgree with 2&3, and thanks for pointing out that documentation, I have no idea why it is written like this. Kedro starters always create tests outside of the
src
because you don't want to ship your test to your user, they don't need this. https://github.com/kedro-org/kedro-starters/tree/main/spaceflights-pandas/%7B%7B%20cookiecutter.repo_name%20%7D%7D
šŸ‘ 1
y

Yury Fedotov

03/26/2024, 11:49 PM
A bit related: @Richard Purvis , see conversation above, remember you told me why in our case it was helpful that Kedro violates the convention of keeping
tests
outside of
src
? Was that related to šŸ§± ?
n

Nok Lam Chan

03/26/2024, 11:52 PM
Unless your application code also need to use the test module. Pytest support both https://docs.pytest.org/en/7.1.x/explanation/goodpractices.html#choosing-a-test-layout-import-rules See "tests as part of application code" and "tests outside application code"
y

Yury Fedotov

03/26/2024, 11:55 PM
I edited my message @Nok Lam Chan , made a typo: a basically meant the opposite šŸ˜…
n

Nok Lam Chan

03/26/2024, 11:56 PM
it was helpful that Kedro violates the convention of keeping
tests
outside of
src
?
Did you mean Kedro created tests outside or inside of
src
?
y

Yury Fedotov

03/26/2024, 11:58 PM
I meant that it creates them inside Which is AFAIK against the common convention But @Richard Purvis might give an example of how it actually was useful for us in the šŸ§± setup
šŸ‘€ 1
r

Richard Purvis

03/27/2024, 12:08 AM
Sure. Were unable to do editable installs inside databricks afaik so having the tests within src made the modules discoverable
2 Views