Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Use temporary directories in unit tests #3377

Merged
merged 7 commits into from
Oct 8, 2023

Conversation

kratman
Copy link
Contributor

@kratman kratman commented Sep 28, 2023

Description

The unit tests leave a large number of files behind in the git repo. This change will make the tests use temporary directories when creating files.

I used the tempfile module in python. There are a few other ways to do this, and I believe the preferred method is to use pytest. However, since pytest does not appear to be used, I went with tempfile as the easy solution.

Type of change

Minor fix in the tests.

  • Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • No style issues: $ pre-commit run (or $ nox -s pre-commit) (see CONTRIBUTING.md for how to set this up to run automatically when committing locally, in just two lines of code)
  • All tests pass: $ python run-tests.py --all (or $ nox -s tests)
  • The documentation builds: $ python run-tests.py --doctest (or $ nox -s doctests)

You can run integration tests, unit tests, and doctests together at once, using $ python run-tests.py --quick (or $ nox -s quick).

Further checks:

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@kratman
Copy link
Contributor Author

kratman commented Sep 28, 2023

This will have conflicts with #3373, so it should be reviewed/merged after that one is complete.

@kratman
Copy link
Contributor Author

kratman commented Sep 29, 2023

Conflicts resolved, this should be ready.

@Saransh-cpp Saransh-cpp self-requested a review September 29, 2023 12:53
@codecov
Copy link

codecov bot commented Sep 29, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (c5aa3ce) 99.56% compared to head (708f721) 99.58%.
Report is 47 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3377      +/-   ##
===========================================
+ Coverage    99.56%   99.58%   +0.01%     
===========================================
  Files          253      254       +1     
  Lines        19561    19817     +256     
===========================================
+ Hits         19476    19734     +258     
+ Misses          85       83       -2     
Files Coverage Δ
pybamm/__init__.py 100.00% <100.00%> (ø)
pybamm/solvers/base_solver.py 100.00% <100.00%> (ø)
pybamm/solvers/idaklu_solver.py 100.00% <100.00%> (+0.90%) ⬆️
pybamm/solvers/processed_variable.py 100.00% <100.00%> (ø)
pybamm/solvers/processed_variable_computed.py 100.00% <100.00%> (ø)
pybamm/solvers/solution.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kratman
Copy link
Contributor Author

kratman commented Oct 1, 2023

Lychee error is unrelated to this change

@kratman
Copy link
Contributor Author

kratman commented Oct 3, 2023

@Saransh-cpp Can this be removed so that these files do not keep getting created when I test?

@Saransh-cpp
Copy link
Member

Sorry for the delay, @kratman, I'll review this before the end of this week. The extra files should not be a problem given that they should be ignored by git? Is there a specific redundant file that is not being ignored in .gitignore?

@kratman
Copy link
Contributor Author

kratman commented Oct 3, 2023

None are missed by gitignore, just they exist until I run a cleanup command

Copy link
Member

@Saransh-cpp Saransh-cpp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, looks amazing, @kratman!

@Saransh-cpp Saransh-cpp merged commit 64d712e into pybamm-team:develop Oct 8, 2023
31 of 32 checks passed
@kratman kratman deleted the feat/useTempDirectories branch October 9, 2023 20:00
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