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

ModuleNotFoundError: No module named 'pytest' #801

Closed
ClaraBuettner opened this issue Jun 8, 2022 · 5 comments
Closed

ModuleNotFoundError: No module named 'pytest' #801

ClaraBuettner opened this issue Jun 8, 2022 · 5 comments
Assignees
Labels
🐛 bug Something isn't working

Comments

@ClaraBuettner
Copy link
Contributor

eGon-data is not running on current dev branch. Manually installing pytest using pip solved the problem.
@nesnoj: It seems to be caused by the e-mob branch. Could you solve this?


 File "<frozen importlib._bootstrap>", line 702, in _load
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/clara/test-egon-data/eGon-data/src/egon/data/airflow/dags/pipeline.py", line 27, in <module>
    from egon.data.datasets.emobility.motorized_individual_travel import (
  File "/home/clara/test-egon-data/eGon-data/src/egon/data/datasets/emobility/motorized_individual_travel/__init__.py", line 95, in <module>
    from egon.data.datasets.emobility.motorized_individual_travel.ev_allocation import (
  File "/home/clara/test-egon-data/eGon-data/src/egon/data/datasets/emobility/motorized_individual_travel/ev_allocation.py", line 29, in <module>
    from egon.data.datasets.emobility.motorized_individual_travel.tests import (
  File "/home/clara/test-egon-data/eGon-data/src/egon/data/datasets/emobility/motorized_individual_travel/tests.py", line 6, in <module>
    import pytest
ModuleNotFoundError: No module named 'pytest'
@ClaraBuettner ClaraBuettner added the 🐛 bug Something isn't working label Jun 8, 2022
@nesnoj
Copy link
Member

nesnoj commented Jun 8, 2022

Hey, oh I thought pytest is part of the requirements already as @gnn also makes use of it here. The test function test_ev_numbers() is for use within the task and requires the DB so I had to mark it to be skipped to make the actions testing happy.
Is there a better approach on this @gnn or can we add pytest to the reqs?

@gnn
Copy link
Collaborator

gnn commented Jun 9, 2022

So, the place I'm using "pytest" is part of the tests. These are not actually part of the installed package, i.e. it's not code which can be reached and run by standard means if you install the package. That's why "pytest" isn't part of the requirements already. It is part of the dev extra requirements, though. So if you do pip install .[dev], or pip install egon-data[dev] once the package has it's first release, "pytest" gets installed. The reason for this is simple: a normal user usually doesn't have a reason to run the tests, whereas a developer should run them. And the dev extra requirements are meant to pull in all packages needed for development in addition to the regular requirements.

The test function test_ev_numbers() is for use within the task and requires the DB so I had to mark it to be skipped to make the actions testing happy. Is there a better approach on this @gnn or can we add pytest to the reqs?

I don't know whether I correctly understand that sentence. Do you mean that the tests unintentionally pick up the test_env_numbers() function and try to run it as a test? If so, this can most easily be fixed by renaming the function. Since the docstring starts with "Validate", the most straightforward solution would be to call it validate_electric_vehicle_numbers. If I understood the problem correctly, that is.

And while I'm at it, some (very) minor points:

  • Having test_ev_numbers() be a link to its definition saves me a bit of time. ;) I know it's just a few seconds because of GitHub's awesome search function, but I first had to figure out how that works again.

  • Please don't use abbreviations like "ev". When I first saw this, I thought it meant "environment". There's no reason not to use "electric_vehicles" instead. And if the variable names get too long, that's a good hint that you should refactor your code to put some of the long names into dedicated methods, classes, modules or similar. There's also a nice post on why not using abbreviations improves readability. It's less than a five minute read and it's even referenced in our contribution guidelines.

  • The correct abbreviation for Not a Number is "NaN".

  • From Python's Docstring Conventions on one-liners:

    The docstring is a phrase ending in a period.

    I know, Git and Python having different conventions for this is whack. Sorry for this.

@gnn
Copy link
Collaborator

gnn commented Jun 9, 2022

Oh and yes, we could potentially add "pytest" to the requirements. But I'd rather avoid that if possible, as our requirements are already rather heavyweight.

@nesnoj
Copy link
Member

nesnoj commented Jun 10, 2022

Thanks a lot for your very extensive answer @gnn !

The test function test_ev_numbers() is for use within the task and requires the DB so I had to mark it to be skipped to make the actions testing happy. Is there a better approach on this @gnn or can we add pytest to the reqs?

I don't know whether I correctly understand that sentence. Do you mean that the tests unintentionally pick up the test_env_numbers() function and try to run it as a test? If so, this can most easily be fixed by renaming the function. Since the docstring starts with "Validate", the most straightforward solution would be to call it validate_electric_vehicle_numbers. If I understood the problem correctly, that is.

You got that right, I renamed the function in afb8adb and kicked out pytest - github action tests in #588 now work out without the marker.

And while I'm at it, some (very) minor points:

  • Having test_ev_numbers() be a link to its definition saves me a bit of time. ;) I know it's just a few seconds because of GitHub's awesome search function, but I first had to figure out how that works again.

I don't understand what you mean by "be a link to its definition".

@nesnoj nesnoj closed this as completed in 21a6f90 Jun 10, 2022
@nesnoj
Copy link
Member

nesnoj commented Jun 10, 2022

I hotfixed it into dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants