question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TST: Do not use random seed in doctest

See original GitHub issue

See https://github.com/astropy/astropy/pull/10644#pullrequestreview-634247783 from @tupui


We did this (#10644) in SciPy and the only difference is that we removed all seeding from examples. This is to enforce best practices. Using small seeds is bad for the entropy of the generator and also common values like 0, 42, 12345 end up in every code which leads to bias in results. Seeing should only be used for testing.

Here I am proposing to remove the seed and just allow variation in the results to pass the doctests (in SciPy I can add # random or # may vary, I am not sure if this is standard or not. Maybe this is your # doctest: +FLOAT_CMP?).

I can do a PR on this branch if you want some help. Also, I would suggest to add somewhere in the doc a paragraph about seeding. See what we did for example https://scipy.github.io/devdocs/tutorial/stats.html#random-number-generation.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
tupuicommented, Jun 23, 2021

Update: It is on the agenda for our “infrastructure tag-ups” but we haven’t gotten around to it yet. Thanks for your continued patience! 😬

Ok thanks for the update! No problem, just let me know 😉

1reaction
tupuicommented, May 4, 2021

FYI, for another reference, I did this for scikit-image here https://github.com/scikit-image/scikit-image/pull/5357

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to doctest random.sample() when used on a set?
Show activity on this post. I am trying to write a doctest for a function that calls random. sample() on a set. Unfortunately,...
Read more >
doctest random output? - Google Groups
Is this a good way to test if random numeric output? It seems to work under Python 2.6 and 3.6 but that doesn't...
Read more >
Random testing - Utilities - SageMath Documentation
Some Sage modules do random testing in their doctests; that is, they construct test cases using a random number generator. To get the...
Read more >
doctest — Test interactive Python examples — Python 3.11.1 ...
The simplest way to start using doctest (but not necessarily the way you'll continue to do it) is to end each module M...
Read more >
Random testing — Sage 9.3.beta9 Reference Manual: Utilities
Some Sage modules do random testing in their doctests; that is, they construct test cases using a random number generator. To get the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found