Skip to content

Conversation

@dwr-zroy
Copy link
Contributor

Description

This PR modifies pyproject.toml and sets a pytest setting to automatically add .\src to the PYTHONPATH. This alleviates the need to modify sys.path when writing test modules.

Tests are passing 100% on my Windows 11 machine, in a Python 3.12 environment. Not sure if there is a larger testing matrix that should be run.

Code Changes

Before

pyproject.toml

[tool.pytest.ini_options]
log_cli = true
log_cli_level = 'INFO'
testpaths = ["tests"]

test_basics.py

"""Pytest module."""

import unittest
import os
import sys

sys.path.append(r'src')
sys.path.append(os.path.dirname(__file__))
from file_manager import FileManager
from hecdss import Catalog, HecDss
from datetime import datetime

...

After

pyproject.toml

[tool.pytest.ini_options]
log_cli = true
log_cli_level = 'INFO'
testpaths = ["tests"]
pythonpath = "./src"

test_basics.py

"""Pytest module."""

import unittest
from datetime import datetime

from file_manager import FileManager

from hecdss import Catalog, HecDss

...

dwr-zroy added 2 commits June 30, 2025 13:58
Following conventions recommended on [pytest](https://docs.pytest.org/en/stable/explanation/goodpractices.html),
setting the `pytest.ini_options.pythonpath` variable in the
pyproject.toml file avoids needed to modify `sys.path` before each
testing module begins.
Clean up the import statements for each testing module.
@oskarhurst
Copy link
Contributor

Hi @dwr-zroy, Thank you for the PR this looks like a good addition to simplify the project.

@oskarhurst oskarhurst merged commit d19d731 into HydrologicEngineeringCenter:main Jul 2, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants