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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:25:56+00:00 2026-05-23T03:25:56+00:00

In one of my functions I’m calling an external program, using subprocess.check_call , which

  • 0

In one of my functions I’m calling an external program, using subprocess.check_call, which will produce output. How could I use doctest to make sure the output it’s producing is the one I’m expecting?

  • 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-23T03:25:56+00:00Added an answer on May 23, 2026 at 3:25 am

    Maybe this can help:

    import sys
    import tempfile
    import subprocess
    
    
    def example(output):
        r""" Do something ...
    
        >>> output = example('Processing file ...')
        >>> print output # doctest:+ELLIPSIS
        'Processing file ...'
    
        Check how many file was processed.
        >>> [line.startswith('Processing file')
        ... for line in output.splitlines()].count(True)
        1    
    
        """
        cmd = "print '%s'" % (output, )
        with tempfile.TemporaryFile() as output:
            subprocess.check_call([sys.executable, '-c', cmd], stdout=output)
            output.seek(0)
            res = output.read()
    
        return res
    
    if __name__ == '__main__':
        import doctest
        doctest.testmod()
    

    As you can see i used the argument stdout of the subprocess.check_call function so to be able to get the output of the command , beside that if you are not using the stdout argument (which i assume that is your case) i think it very hard to capture the command output.

    Hope this was hopeful 🙂

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

Sidebar

Related Questions

I wanted to write two one-line functions which will trim white spaces from left
I have VB.net windows service and in one of the functions I am using
I am extending Python with some C++ code. One of the functions I'm using
One concept I've always wondered about is the use of cryptographic hash functions and
One of the functions in the API I am using is returning basically just
How to use One way hash functions in T-SQL (Microsoft SQL) for Hash data
I have several user defined table-valued functions and one view which has the same
This is one of the most used Regex functions Regex.IsMatch(Test text for regex test.,
I have 2 functions that needs to be executed one after the other. In
Can hover and click functions be combined into one, so for example: click: $('#target').click(function()

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.