Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 990491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:57:17+00:00 2026-05-16T05:57:17+00:00

Hello i was wondering if it is possible and if so how? to do

  • 0

Hello i was wondering if it is possible and if so how? to do doctests or something similar from the mainline, instead of testing a function as is described in the doctest docs
i.e.

"""
>>> 
Hello World
"""

if __name__ == "__main__":
    print "Hello"
    import doctest
    doctest.testmod()

This is part of being able to test students scripts against a docstring, i found this snipet of code that allows me to input both as strongs

import doctest
from doctest import DocTestRunner, DocTestParser
enter code here
def run_doctest(code, test):
    import doctest
    from doctest import DocTestRunner, DocTestParser
    code = code + '\n__dtest=__parser.get_doctest(__test, globals(), "Crunchy Doctest", "crunchy", 0)\n__runner.run(__dtest)\n'
    runner = DocTestRunner()
    parser = DocTestParser()
    exec code in {'__runner':runner, '__parser':parser, '__test':test}

that does more or less but it seems hardly ideal, an suggestions on either point

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:57:18+00:00Added an answer on May 16, 2026 at 5:57 am

    doctest is not limited to testing functions. For example, if dt.py is:

    '''
      >>> foo
      23
    '''
    
    foo = 23
    
    if __name__ == '__main__':
        import doctest
        doctest.testmod()
    

    then, e.g.:

    $ py26 dt.py -v
    Trying:
        foo
    Expecting:
        23
    ok
    1 items passed all tests:
       1 tests in __main__
    1 tests in 1 items.
    1 passed and 0 failed.
    Test passed.
    

    (works just as well without the -v, but then it wouldn’t have much to show: just silence;-). Is this what you’re looking for?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if it were possible to, instead of selecting an element from
I have Hello World code that uses function fhi from another hi.cpp file that
I was wondering if is is possible to send output from application ran by
I was wondering if it's possible to have a function in a class, that
Hello I was wondering if it was possible to store a double into a
I was wondering if something like the following would be possible in PHP: <?php
Hello I am wondering whether it is possible to do this type of regex:
Possible Duplicate: How do I tokenize a string in C++? Hello I was wondering
Hello People of Stackoverflow, I was wondering if it was possible to compile a
I was wondering if it would be possible to get the page name from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.