Skip to content

Conversation

@nickromano
Copy link
Contributor

I have added an option to allow a user to specify a threshold so only tests slower than SLOW_TEST_THRESHOLD_MS will be shown.

Without specifying the setting the slowest tests will always show as expected.

$ python manage.py test
Creating test database for alias 'default'...
..........
----------------------------------------------------------------------
Ran 10 tests in 0.413s

OK
Destroying test database for alias 'default'...

10 slowest tests:
0.3597s test_detail_view_with_a_future_poll (polls.tests.PollIndexDetailTests)
0.2843s test_detail_view_with_a_past_poll (polls.tests.PollIndexDetailTests)
0.0068s test_index_view_with_a_future_poll (polls.tests.PollViewTests)
0.0047s test_index_view_with_a_past_poll (polls.tests.PollViewTests)
0.0045s test_index_view_with_two_past_polls (polls.tests.PollViewTests)
0.0041s test_index_view_with_future_poll_and_past_poll (polls.tests.PollViewTests)
0.0036s test_index_view_with_no_polls (polls.tests.PollViewTests)
0.0003s test_was_published_recently_with_future_poll (polls.tests.PollMethodTests)
0.0002s test_was_published_recently_with_recent_poll (polls.tests.PollMethodTests)
0.0002s test_was_published_recently_with_old_poll (polls.tests.PollMethodTests)

But if you have the option to specify for example SLOW_TEST_THRESHOLD_MS = 200 then only tests slower than this limit will show:

$ python manage.py test
Creating test database for alias 'default'...
..........
----------------------------------------------------------------------
Ran 10 tests in 0.413s

OK
Destroying test database for alias 'default'...

2 slowest tests over 200ms:
0.3597s test_detail_view_with_a_future_poll (polls.tests.PollIndexDetailTests)
0.2843s test_detail_view_with_a_past_poll (polls.tests.PollIndexDetailTests)

And if there are no tests above the threshold you will see the following message (for example if SLOW_TEST_THRESHOLD_MS is set to 400):

$ python manage.py test
Creating test database for alias 'default'...
..........
----------------------------------------------------------------------
Ran 10 tests in 0.413s

OK
Destroying test database for alias 'default'...

No tests slower than 400ms

Please let me know if you have any questions!

Thank you,
Nick

@coveralls
Copy link

coveralls commented Nov 30, 2016

Coverage Status

Coverage decreased (-17.8%) to 66.154% when pulling d44c100 on nickromano:timing-threshold into 45a86b8 on realpython:master.

1 similar comment
@coveralls
Copy link

coveralls commented Nov 30, 2016

Coverage Status

Coverage decreased (-17.8%) to 66.154% when pulling d44c100 on nickromano:timing-threshold into 45a86b8 on realpython:master.

@coveralls
Copy link

coveralls commented Nov 30, 2016

Coverage Status

Coverage decreased (-17.8%) to 66.154% when pulling d44c100 on nickromano:timing-threshold into 45a86b8 on realpython:master.

@nickromano nickromano changed the title Allow the user to filter slow tests under a threshold Allow the user to filter slow tests above a threshold Nov 30, 2016
@nickromano
Copy link
Contributor Author

If anyone has an idea of how to run and check the teardown_test_environment method in django_slowtests.tests.tests please let me know!

I'd be happy to write test cases for it.

@mjhea0 mjhea0 merged commit c9b4ed3 into realpython:master Nov 30, 2016
@nickromano nickromano deleted the timing-threshold branch March 16, 2017 07:33
@nickromano
Copy link
Contributor Author

@mjhea0 Thanks again for the quick merge. Would it be possible to bump the package version number and upload to pypi?

@mjhea0
Copy link
Contributor

mjhea0 commented Mar 16, 2017

@nickromano
Copy link
Contributor Author

@mjhea0 Awesome thank you!

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

Successfully merging this pull request may close these issues.

3 participants