diff --git a/pyproject.toml b/pyproject.toml index 3c8646a..85bd93d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,9 +14,11 @@ dev = [ "pre-commit>=4.2.0", "ruff>=0.11.4", "pytest>=7.0", + "pytest-profiling", + "flameprof", ] [tool.pytest.ini_options] testpaths = ["tests"] python_files = "test_*.py" -addopts = "-v" +addopts = "-v -m 'not profiling'" diff --git a/src/dementpy.py b/src/dementpy.py index c04f8b6..daa0148 100644 --- a/src/dementpy.py +++ b/src/dementpy.py @@ -103,4 +103,5 @@ def main(): os.chdir('../'+output_folder) export(Output_init, site, outname) -main() \ No newline at end of file +if __name__ == '__main__': + main() diff --git a/tests/profiling/test_profiling.py b/tests/profiling/test_profiling.py new file mode 100644 index 0000000..5a00973 --- /dev/null +++ b/tests/profiling/test_profiling.py @@ -0,0 +1,18 @@ +"""Test(s) to use with pytest-profiling to identify bottlenecks in the code.""" +import pytest + +@pytest.mark.profiling +def test_profiling(monkeypatch): + + # Define the command line arguments + import sys + argv = ['dementpy.py', 'grassland', 'output', '20250402', 'scrubland'] + monkeypatch.setattr(sys, 'argv', argv) + + # Move to subfolder so input and output folders will be correct + import os + os.chdir('src') + + # Run dementpy + import dementpy + dementpy.main() diff --git a/tests/test_grid.py b/tests/unit/test_grid.py similarity index 100% rename from tests/test_grid.py rename to tests/unit/test_grid.py diff --git a/tests/test_initialization.py b/tests/unit/test_initialization.py similarity index 100% rename from tests/test_initialization.py rename to tests/unit/test_initialization.py diff --git a/tests/test_placeholder.py b/tests/unit/test_placeholder.py similarity index 100% rename from tests/test_placeholder.py rename to tests/unit/test_placeholder.py