Python: Is it possible to test only specific functions with doctest in a module?

I am trying to get tested in python using the doctest module. At the moment I'm doing

  • Write tests for functions.
  • implement function code.
  • If the tests pass, write more tests and more code.
  • When the function is executed, go to the next function to implement.

So, after 3 or 4 (independent) functions in the same module with many tests, I get a huge output from doctest. And it's a little annoying.

Is there a way to tell doctest to "not test the functions a() , b() and c() " so that it only runs unmarked functions?

I found only the doctest.SKIP flag, which is not enough for my needs. I would need to place this flag in many lines. And if I wanted to check the function marked again, I would have to manually go through the code and remove any flag that I set inside ...

I hope you understand what I mean ... :-)

Any suggestions?

+10
source share
1 answer

looks like you can pass the function run_docstring_examples :

 def f(a, b, c): ''' >>> f(1,2,3) 42 ''' if __name__ == '__main__': import doctest # doctest.testmod() doctest.run_docstring_examples(f, globals()) 

example found through google.

+13
source

Source: https://habr.com/ru/post/1011492/


All Articles