-
Notifications
You must be signed in to change notification settings - Fork 913
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change example test on default template (#4368)
* Change example test on default template Signed-off-by: Laura Couto <[email protected]> * Lint Signed-off-by: Laura Couto <[email protected]> * Account for extra files in tests Signed-off-by: Laura Couto <[email protected]> * Adapt unit tests to new template Signed-off-by: Laura Couto <[email protected]> * Adapt e2e test Signed-off-by: Laura Couto <[email protected]> * Change test to work with no example pipeline Signed-off-by: Laura Couto <[email protected]> * Change test_a_project.md example test Signed-off-by: Laura Couto <[email protected]> * Lint Signed-off-by: Laura Couto <[email protected]> * Update docs/source/development/automated_testing.md Co-authored-by: Merel Theisen <[email protected]> Signed-off-by: L. R. Couto <[email protected]> --------- Signed-off-by: Laura Couto <[email protected]> Signed-off-by: L. R. Couto <[email protected]> Co-authored-by: Merel Theisen <[email protected]>
- Loading branch information
Showing
2 changed files
with
29 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 17 additions & 34 deletions
51
kedro/templates/project/{{ cookiecutter.repo_name }}/tests/test_run.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,25 @@ | ||
""" | ||
This module contains an example test. | ||
This module contains example tests for a Kedro project. | ||
Tests should be placed in ``src/tests``, in modules that mirror your | ||
project's structure, and in files named test_*.py. They are simply functions | ||
named ``test_*`` which test a unit of logic. | ||
To run the tests, run ``pytest`` from the project root directory. | ||
project's structure, and in files named test_*.py. | ||
""" | ||
|
||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from kedro.config import OmegaConfigLoader | ||
from kedro.framework.context import KedroContext | ||
from kedro.framework.hooks import _create_hook_manager | ||
from kedro.framework.project import settings | ||
|
||
|
||
@pytest.fixture | ||
def config_loader(): | ||
return OmegaConfigLoader(conf_source=str(Path.cwd() / settings.CONF_SOURCE)) | ||
|
||
|
||
@pytest.fixture | ||
def project_context(config_loader): | ||
return KedroContext( | ||
package_name="{{ cookiecutter.python_package }}", | ||
project_path=Path.cwd(), | ||
env="local", | ||
config_loader=config_loader, | ||
hook_manager=_create_hook_manager(), | ||
) | ||
|
||
from pathlib import Path | ||
from kedro.framework.session import KedroSession | ||
from kedro.framework.startup import bootstrap_project | ||
|
||
# The tests below are here for the demonstration purpose | ||
# and should be replaced with the ones testing the project | ||
# functionality | ||
class TestProjectContext: | ||
def test_project_path(self, project_context): | ||
assert project_context.project_path == Path.cwd() | ||
|
||
class TestKedroRun: | ||
def test_kedro_run_no_pipeline(self): | ||
# This example test expects a pipeline run failure, since | ||
# the default project template contains no pipelines. | ||
bootstrap_project(Path.cwd()) | ||
|
||
with pytest.raises(Exception) as excinfo: | ||
with KedroSession.create(project_path=Path.cwd()) as session: | ||
session.run() | ||
|
||
assert "Pipeline contains no nodes" in str(excinfo.value) |