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 8387121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:07:37+00:00 2026-06-09T18:07:37+00:00

I want to run Python’s doctest on a .txt file (ie, not on docstring),

  • 0

I want to run Python’s doctest on a .txt file (ie, not on docstring), but I don’t want to go to the command line.

python -m doctest myfile.txt

The reason I don’t want to do it from the command line is that I just don’t want to leave Visual Studio. I want to run it with F5 and then see my output in VS as well.

Question: How can I run doctest from a .py file, then, not from the command line?

  • 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-06-09T18:07:39+00:00Added an answer on June 9, 2026 at 6:07 pm

    check out doctest.testfile. I think that will do what you want…

    Here’s the some of the source from doctest.py for example usage:

    def _test():
        testfiles = [arg for arg in sys.argv[1:] if arg and arg[0] != '-']
        if not testfiles:
            name = os.path.basename(sys.argv[0])
            if '__loader__' in globals():          # python -m
                name, _ = os.path.splitext(name)
            print("usage: {0} [-v] file ...".format(name))
            return 2
        for filename in testfiles:
            if filename.endswith(".py"):
                # It is a module -- insert its dir into sys.path and try to
                # import it. If it is part of a package, that possibly
                # won't work because of package imports.
                dirname, filename = os.path.split(filename)
                sys.path.insert(0, dirname)
                m = __import__(filename[:-3])
                del sys.path[0]
                failures, _ = testmod(m)
            else:
                failures, _ = testfile(filename, module_relative=False)
            if failures:
                return 1
        return 0
    
    
    if __name__ == "__main__":
        sys.exit(_test())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to run a command line program from within a python script and
I want to be able to run my Python project from the command line.
I want to set up a cron job to run a python script, but
I have a python program/file that I want to run repeatedly and calculate the
I want to run the following bash command in Python 3: ls -l I
I want to run a csh file from a python script, example, #!/usr/bin/python import
I want to run the 'time' unix command from a Python script, to time
I want to run three commands at the same time from python. The command
I want to run: python somescript.py somecommand But, when I run this I need
Background: I mostly run python scripts from the command line in pipelines and so

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.