-
Notifications
You must be signed in to change notification settings - Fork 250
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
Unit test base network #1438
Unit test base network #1438
Conversation
for more information, see https://pre-commit.ci
…/pypsa-eur into unit_test_base_network
for more information, see https://pre-commit.ci
…/pypsa-eur into unit_test_base_network
…_test_base_network
for more information, see https://pre-commit.ci
…/pypsa-eur into unit_test_base_network
…_test_base_network
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for continuing the unit testing journey @finozzifa!
I was mostly just skimming through things, but looks good to me.
If you haven't already done so locally, we could think about integrating codecov like in the other package repos. See here. Not as a check (yet), but just to get an overview to focus on the most useful tests.
@@ -28,3 +30,89 @@ def config(): | |||
with open(path_config, "r") as file: | |||
config_dict = yaml.safe_load(file) | |||
return config_dict | |||
|
|||
|
|||
@pytest.fixture(scope="function") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have any best practices for choosing scopes? I think the function
scope works well for DataFrames because they initialise quickly. But in PyPSA I've been playing around with the scope of test networks because they are sometimes modified and sometimes not in the tests, which adds up if function
is used as scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And same goes for the two network fixtures you created here already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @lkstrp,
indeed great question!
I usually used function being the default one and (most likely) the safest one.
However, now that I think about it, the config
fixture can be initialized only once per test session. Changing the scope for this fixture actually leads to a speed up of the test execution (almost 30%). You can find the results below. The scope session and package behave equally well.
This is of course not very relevant now, but it will become once we add more and more tests.
@pytest.fixture(scope="function")
def config():
hyperfine pytest test
Time (mean ± σ): 2.223 s ± 0.108 s [User: 1.949 s, System: 0.251 s]
Range (min … max): 2.106 s … 2.459 s 10 runs
@pytest.fixture(scope="session")
def config():
hyperfine pytest test
Time (mean ± σ): 1.568 s ± 0.004 s [User: 1.333 s, System: 0.228 s]
Range (min … max): 1.563 s … 1.573 s 10 runs
@pytest.fixture(scope="package")
def config():
hyperfine pytest test
Time (mean ± σ): 1.570 s ± 0.003 s [User: 1.334 s, System: 0.229 s]
Range (min … max): 1.567 s … 1.574 s 10 runs
Closes # (if applicable).
Changes proposed in this Pull Request
The pull request proposes the following unit tests:
test/test_base_network.py:
Checklist
envs/environment.yaml
.config/config.default.yaml
.doc/configtables/*.csv
.doc/data_sources.rst
.doc/release_notes.rst
is added.