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

[Testing] Add Pytest.ini file in Python Directory for Local Pytest Configuration #2539

Closed
BethanyG opened this issue Sep 4, 2021 · 4 comments
Assignees
Labels
improve documentation 💖 specific improvements to documentation on the track, the exercises, or the repo. x:action/improve Improve existing functionality/content x:size/small Small amount of work x:status/claimed Someone is working on this issue

Comments

@BethanyG
Copy link
Member

BethanyG commented Sep 4, 2021

Since we're using a custom pytest.marks.task(taskno) for our Concept exercise tests, we need to have a way for CLI users to register them. Otherwise, PyTest complains for every test locally (see issue #2536).

The most expedient way to do this is to provide a pytest.ini file as part of the python exercise directory.
If we'd rather not do it in the main exercism/python folder, we could add it into exercism/python/exercise or exercism/python/exercises/concept.
Additionally, we should update the documentation to show users how to register or ignore the marks themselves.

The ini file should include:

[pytest]
markers =
    task: A concept exercise task.
@BethanyG BethanyG added bug 🐛 improve documentation 💖 specific improvements to documentation on the track, the exercises, or the repo. x:action/improve Improve existing functionality/content x:size/small Small amount of work claimed 🐾 For new exercises being written by contributors and maintainers. x:status/claimed Someone is working on this issue labels Sep 4, 2021
@BethanyG BethanyG self-assigned this Sep 4, 2021
@BethanyG BethanyG changed the title Add Pytest.ini file in Python Directory for Local Pytest Configuration [Testing] Add Pytest.ini file in Python Directory for Local Pytest Configuration Sep 4, 2021
@BethanyG
Copy link
Member Author

BethanyG commented Sep 5, 2021

Further techniques to add to documentation (thank you to @kbuc for these) :

One can also run with pytest -o markers=task or put it in an environmental variable PYTEST_ADDOPTS .
Especially easy for those running in an pipenv virtual environment.

@siebenschlaefer
Copy link
Contributor

Why was this issue closed?

The file HELP.md still says

To run the included tests, run the test file using the pytest module, replacing {exercise_name}:

$ python3 -m pytest {exercise_name}_test.py

And if I do that I get tons of warnings:

========================================= warnings summary ==========================================
classes_test.py:15
  /exercise_test.py:15: PytestUnknownMarkWarning: Unknown pytest.mark.task - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html
    @pytest.mark.task(taskno=1)
...

Of course, if I start to look around there's a link in HELP.md:

For more information about running tests using pytest, checkout our Python testing guide.

and at the end of that lengthy document there's a section Fixing warnings.

That's not a great user experience. If I as an experienced developer find that bothersome and had to spend some time to find that paragraph how must that feel for a beginner?

To quote Raymond Hettinger: "There must be a better way", right?

@BethanyG
Copy link
Member Author

Hi @siebenschlaefer -- Thanks for the poke. 😄 YES -- there is indeed a better way -- and I need to follow up on it. See issue #2745 -- which is a similar issue outlining what we will ultimately do (and why we closed this issue): have the said pytest.ini file downloaded as part of the CLI, and have instructions on how to place it in the correct position to silence the warnings.

But more to your point: we also need to change the HELP.md and Python testing guide to have different instructions up front on how to run pytest so that the warnings don't happen, along with instructions on how to download/create and place the pytest.ini file while we work on having it download automatically.

I'll go ahead and create those issues later today my time. Meanwhile, since this issue is about creating the pytest.ini file in this repo -- not about giving students instructions on how to configure pytest -- I am going to leave it in [closed] state but link it to the other issues, to keep things together.

@BethanyG BethanyG removed bug 🐛 claimed 🐾 For new exercises being written by contributors and maintainers. labels Feb 19, 2022
@BethanyG
Copy link
Member Author

BethanyG commented Apr 1, 2022

@siebenschlaefer - I've made updates to exercises/shared/.docs/tests.md and /docs/TESTING.md. Would love any feedback you have to give on either document wrt clarity around pytest markers. Many thanks for your help!.

@ErikSchierboom - any update on whether or not we've got the pytest.ini file download via the CLI? I'll want to change the directions once it starts downloading....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improve documentation 💖 specific improvements to documentation on the track, the exercises, or the repo. x:action/improve Improve existing functionality/content x:size/small Small amount of work x:status/claimed Someone is working on this issue
Projects
None yet
Development

No branches or pull requests

2 participants