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

How to unit-test infinite loops? #955

Closed
Tontyna opened this issue Oct 1, 2019 · 4 comments
Closed

How to unit-test infinite loops? #955

Tontyna opened this issue Oct 1, 2019 · 4 comments

Comments

@Tontyna
Copy link
Contributor

Tontyna commented Oct 1, 2019

Lately I started setup.py test. It was the first time since about half a year. I know it's a lengthy task, it's tea-time, Sir. But this time I could bake a cake while the unit tests run and ate almost all memory.

Eventually, after more than half an hour I killed the process. Was tired to stare at

weasyprint\tests\test_layout\test_inline.py ss.x.....

Yeah, I guess the beloved test_breaking_linebox_regression_*s are expensive, expensive, expensive.

But the latest successful Win build on travis only took 4 min 19 sec!

What's wrong with my system? It's 64bit Windows 7 (rebooted), Python 3.6 and Python 3.7, site-packages up-to-date.

Any advice? Other than not running unit tests at all?

@Tontyna
Copy link
Contributor Author

Tontyna commented Oct 1, 2019

Nothing wrong with my system, nothing wrong with pytest!

I tried to pytest a branch that introduced an infinite loop in test_inline.py -- will rename this issue.

@Tontyna Tontyna changed the title Are unit tests supposed to cripple my system? How to unit-test infinitive loops? Oct 1, 2019
@Tontyna Tontyna changed the title How to unit-test infinitive loops? How to unit-test infinite loops? Oct 1, 2019
@Tontyna
Copy link
Contributor Author

Tontyna commented Oct 1, 2019

Counting the dots finally disclosed test_breaking_linebox_regression_3() to be the hanging test. This test is a regression test for #560 and indeed my branch got stuck. Okay, regression to infinite loop prevented by infinite loop.

Of course a hanging layout-loop cannot be reported by assert statements (though there are 5 asserts to check the correct line breaks), but isn't there a pytest mark or decorator to stop (and report) a test that exceeds a certain time or memory limit?

@knixeur
Copy link

knixeur commented Nov 26, 2019

You could use unittest.mock.patch with side effect emulate a certain amount of return values and check that you never run out, but that will probably involve a lot of refactor. An easier solution and exactly what you're looking for is https://pypi.org/project/pytest-timeout/

@Tontyna
Copy link
Contributor Author

Tontyna commented Dec 6, 2019

Yes, pytest-timeout seems to be the only way to do that -- but I'm not convinced that the effort of implementing it in the test suite is worth the improvement.

@Tontyna Tontyna closed this as completed Dec 6, 2019
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