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

Issue when the test asks for prompt #97

Open
broxane opened this issue Mar 5, 2019 · 5 comments
Open

Issue when the test asks for prompt #97

broxane opened this issue Mar 5, 2019 · 5 comments

Comments

@broxane
Copy link

broxane commented Mar 5, 2019

Hi, it's me again, and it is again about a django-related behaviour.

Sometimes, when you stop a test with ctrl+C (or when the test failed to execute, for instance because of a syntax error), the test database could not be exited properly, so the next time a test is run, you have this prompt :

Creating test database for alias 'default'...
Got an error creating the test database: database "test" already exists

Type 'yes' if you would like to try deleting the test database 'test', or 'no' to cancel: 

Mutmut does not like it very much :

  • At phase 1 - mutmut wait indefinitely
  • At phase 2 - the test is considered as timeout ⏰
@broxane
Copy link
Author

broxane commented Mar 5, 2019

Once again, sorry for approximate english

@broxane broxane changed the title Issue when the test ask for prompt Issue when the test asks for prompt Mar 5, 2019
@boxed
Copy link
Owner

boxed commented Mar 5, 2019

Interesting. I find it a bit weird that you'd end up in that state due to a syntax error in the source code, but let's leave that aside as you already have issues open for that..

I guess we could be gentler when shutting down. Maybe sending a signal to the testing process and waiting for a timeout. The user could kill hard by pressing ctrl+c again. We should make it clear that we are waiting and that you can kill hard with a second ctrl+c.

@broxane
Copy link
Author

broxane commented Mar 5, 2019

As I see it, the issue is more about reacting when the test asks for a prompt, rather than exiting gently, especially when it can be due to another suit of tests... Do you see what I mean ?

@boxed
Copy link
Owner

boxed commented Mar 5, 2019

I think that needs to be fixed too, but if we just handle this you'll still not be able to get this to work.

@bskinn
Copy link
Contributor

bskinn commented Apr 21, 2019

@broxane As a shim for this hangup, you may be able to use my stdio_mgr package within your test function/method... it patches out stdin, as well as stdout/stderr. You preload stdin with a response to the prompt, which is supplied when the enclosed code calls input():

from stdio_mgr import stdio_mgr
with stdio_mgr("yes\n") as (in_, out_, err_):
    {code for creating 'test' database, consuming the provided "yes\n"}
    # If you want, you could test for the database-exists prompt with something like:
    assert 'database "test" already exists' in out_.getvalue()

The test should still run fine (without that above assert) even if the 'yes/no' prompt doesn't occur, b/c the pre-loaded "yes\n" would just be discarded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants