I am getting some kind of environmental variable o...
# questions
g
I am getting some kind of environmental variable or config issue. The module for the project cannot be found. At first I thought it was just one project, but it seems to be something broader. On my system even creating a fresh project gives the same error. 1. I create a venv, and activate it. 2. Install kedro (pip install kedro), which is currently giving 0.19.9 3. Initialize new kedro project. 4. Run pytest (which gives a module not found error for the very project I just created). Troubleshooting advice would be appreciated.
j
hi @Galen Seilis, seems like you're missing 1 step which is installing your own project
something like
pip install --editable .
(with
.
being the path where
pyproject.toml
is)
otherwise
pytest
won't find any local modules you have under
src/{project_name}
could you try that?
g
Sure! Will try that now.
j
(to clarify, between (3) and (4))
g
@Juan Luis On a new project
kedro_foo
I got this after following the steps (including running
pip install --editable .
)
Copy code
\kedro_foo\foo> pytest
\kedro_foo\venv\lib\site-packages\_pytest\config\__init__.py:331: PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
Plugin: helpconfig, Hook: pytest_cmdline_parse
UsageError: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --cov-report --cov src/foo
  inifile: \kedro_foo\foo\pyproject.toml
  rootdir: \kedro_foo\foo
For more information see <https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning>
  config = pluginmanager.hook.pytest_cmdline_parse(
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --cov-report --cov src/foo
  inifile: \kedro_foo\foo\pyproject.toml
  rootdir: \kedro_foo\foo
Oh, sorry the project is called
foo
.
kedro foo
is just a folder I made above it.
j
"unrecognized arguments --cov-report --cov" looks like pytest is mandating those extra args (maybe
addopts
in the pytest conf) and you don't have
pytest-cov
installed
you can either
pip install pytest-cov
or tweak the pytest config
g
Ah, good idea. I see that it is not in my
requirements.txt
. I will try installing
pytest-cov
and then running
pytest
again.
j
g
@Juan Luis Okay, that definitely changed the error:
Copy code
> pytest
================================================= test session starts =================================================
platform win32 -- Python 3.10.4, pytest-7.4.4, pluggy-1.5.0
rootdir: \kedro_foo\foo
configfile: pyproject.toml
plugins: anyio-3.7.1, cov-5.0.0
collected 1 item

tests\test_run.py E                                                                                              [100%]\kedro_foo\venv\lib\site-packages\coverage\control.py:894: CoverageWarning: No data was collected. (no-data-collected)
  self._warn("No data was collected.", slug="no-data-collected")


======================================================= ERRORS ========================================================
_______________________________ ERROR at setup of TestProjectContext.test_project_path ________________________________

config_loader = OmegaConfigLoader(conf_source=\kedro_foo\foo, env=None, runtime_params={}, config_patterns={'catalog': ['c.../credentials*'], 'globals': ['globals.yml']}, base_env=), default_run_env=), custom_resolvers=None), merge_strategy={})

    @pytest.fixture
    def project_context(config_loader):
>       return KedroContext(
            package_name="foo",
            project_path=Path.cwd(),
            config_loader=config_loader,
            hook_manager=_create_hook_manager(),
        )
E       TypeError: KedroContext.__init__() missing 1 required positional argument: 'env'

tests\test_run.py:23: TypeError

---------- coverage: platform win32, python 3.10.4-final-0 -----------
Name                            Stmts   Miss  Cover   Missing
-------------------------------------------------------------
src\foo\__init__.py                 1      1     0%   4
src\foo\__main__.py                14     14     0%   4-24
src\foo\pipeline_registry.py        7      7     0%   2-16
src\foo\pipelines\__init__.py       0      0   100%
src\foo\settings.py                 7      7     0%   15-37
-------------------------------------------------------------
TOTAL                              29     29     0%

=============================================== short test summary info ===============================================
ERROR tests/test_run.py::TestProjectContext::test_project_path - TypeError: KedroContext.__init__() missing 1 required positional argument: 'env'
================================================== 1 error in 1.17s ===================================================
This is my
pyproject.toml
Copy code
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "foo"
readme = "README.md"
dynamic = ["dependencies", "version"]

[project.scripts]
foo = "foo.__main__:main"

[project.entry-points."kedro.hooks"]

[project.optional-dependencies]
docs = [
    "docutils<0.21",
    "sphinx>=5.3,<7.3",
     "sphinx_rtd_theme==2.0.0",
    "nbsphinx==0.8.1",
    "sphinx-autodoc-typehints==1.20.2",
    "sphinx_copybutton==0.5.2",
    "ipykernel>=5.3, <7.0",
    "Jinja2<3.2.0",
    "myst-parser>=1.0,<2.1"
]
dev = [
    "pytest-cov~=3.0",
    "pytest-mock>=1.7.1, <2.0",
    "pytest~=7.2",
    "ruff~=0.1.8"
]

[tool.setuptools.dynamic]
dependencies = {file = "requirements.txt"}
version = {attr = "foo.__version__"}

[tool.setuptools.packages.find]
where = ["src"]
namespaces = false

[tool.kedro]
package_name = "foo"
project_name = "foo"
kedro_init_version = "0.19.8"
tools = ['Linting', 'Testing', 'Custom Logging', 'Documentation', 'Data Structure', 'Kedro Viz']
example_pipeline = "False"
source_dir = "src"

[tool.pytest.ini_options]
addopts = """
--cov-report term-missing \
--cov src/foo -ra"""

[tool.coverage.report]
fail_under = 0
show_missing = true
exclude_lines = ["pragma: no cover", "raise NotImplementedError"]

[tool.ruff.format]
docstring-code-format = true

[tool.ruff]
line-length = 88
show-fixes = true
select = [
    "F",   # Pyflakes
    "W",   # pycodestyle
    "E",   # pycodestyle
    "I",   # isort
    "UP",  # pyupgrade
    "PL",  # Pylint
    "T201", # Print Statement
]
ignore = ["E501"]  # Ruff format takes care of line-too-long
n
ERROR tests/test_run.py:TestProjectContext:test_project_path - TypeError: KedroContext.__init__() missing 1 required positional argument: 'env'
Can you pass in a value there?
env=None
?
g
@Nok Lam Chan Certainly. I just tried it and the error was removed. Curiously, I did not touch that file at all since creating the dummy project
foo
. Is this something to change on the Kedro end, or something wrong with my setup? (I ran
kedro new
and then followed the prompts).
Or an issue that I had not yet created a pipeline in project
foo
?
j
this was fixed 3 weeks ago https://github.com/kedro-org/kedro/pull/4159 will see the light in the new release 🙏🏼
❤️ 1
g
Excellent! 🎉 Not a hard fix in the time being.
❤️ 1
125 Views