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

[Guidos Gorgeous Lasagna]: Tests Fail With Confusing pytest error if Student uses input() #101

Open
CodebyKhayla opened this issue Apr 21, 2022 · 7 comments
Assignees

Comments

@CodebyKhayla
Copy link

clicked "Run Tests" Got the following error:

We received the following error when we ran your code:
OSError: pytest: reading from stdin while output is captured! Consider using -s.

@github-actions

This comment was marked as resolved.

@BethanyG
Copy link
Member

Hi @CodebyKhayla 👋🏽

Thank you for filing this issue! That is indeed concerning. I'm assuming that you tested your code via the website (please let me know if that's not the case). When I tried that exercise through the UI just now, I didn't receive that error - but that doesn't mean we don't have a problem.

Could you possibly provide the code you were testing, and any other details you can remember? That would be super helpful in tracking this down. Many thanks.

@CodebyKhayla
Copy link
Author

Hi @BethanyG !

Wow, thanks for getting back to me so quickly. I definitely think my code is still not the right answer to the exercise, however, here is a screenshot.

image

@BethanyG
Copy link
Member

Hi @CodebyKhayla

Your code does indeed have an issue. On line 9, you are defining a parameter that accepts interactive arguments from the command line (I am assuming as a test on your own system??). input() is something that you should in general be very cautious using. You must always intercept and check data from input(), as you cannot control what a user will type, and you must always sanitize anything before putting it to use in your program.

Our tests and testing framework are not designed for this sort of parameter, and (as you can see by the error thrown) pytest as we run it failed out because of the interactive prompt. All tests run in an isolated environment and that environment does not accept input from stdin or a command prompt.

We might examine blocking that feature of Python altogether in our test environment so that other users don't get confused by the pytest error. We don't have any exercises that deal with input(), and are not likely to add any in the near future.

Meanwhile, commenting out line 9 should get the tests to run for you. Let me know if that doesn't fix the problem.

@CodebyKhayla
Copy link
Author

Thanks @BethanyG ! I definitely thought it was because of something I was doing.

Could it maybe be added to the instructions to not include input()?

Either way, thanks again, you've been amazing

@BethanyG
Copy link
Member

Could it maybe be added to the instructions to not include input()?

🤔 As you have probably seen, the directions for this exercise are already quite long, and many students don't read them through to the end. Although maybe adding a comment in the stub to remind people could be a good addition. I will think about it.

We may need to just be up front with students and have a general doc that outlines the dos and don'ts of our online system. Neither input() nor print() generally work for any of our exercises (on the Python track at least). All of our exercises expect the use of return statements.

We will probably have exercises that do use print() in the future, but they will be purpose-built to have tests that check stdout, and are not on our immediate roadmap.

I'll keep this with a "bug" flag while I take a bit to think what we might want to do here. Thanks again for filing the issue -- and for providing the additional information!

@BethanyG BethanyG changed the title Cannot run tests on "Guido's Gorgeous Lasagna" [Guidos Gorgeous Lasagna]: Tests Fail With Confusing pytest error if Student uses input() Apr 21, 2022
@BethanyG BethanyG self-assigned this May 17, 2022
@BethanyG BethanyG transferred this issue from exercism/python May 21, 2022
@BethanyG
Copy link
Member

Transferred issue here, because it most likely needs a solution in the runner.

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

No branches or pull requests

2 participants