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

  • Home
  • SEARCH
  • 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 8841071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:37:13+00:00 2026-06-14T10:37:13+00:00

I’m running py.test on Linux in the context of a module that makes heavy

  • 0

I’m running py.test on Linux in the context of a module that makes heavy usage of multiprocessing. Exceptions in child processes are not detected as an error. Example test file pytest_mp_test.py:

import multiprocessing

def test_mp():
    p = multiprocessing.Process(target=child)
    p.start()
    p.join()

def child():
    assert False

Execution:

$ py.test pytest_mp_test.py 
================================== test session starts ===================================
platform linux2 -- Python 2.7.3 -- pytest-2.3.3
plugins: cov
collected 1 items 

pytest_mp_test.py .

================================ 1 passed in 0.04 seconds ================================

No error detected. The exception is printed when invoked with -s:

$ py.test -s pytest_mp_test.py 
================================== test session starts ===================================
platform linux2 -- Python 2.7.3 -- pytest-2.3.3
plugins: cov
collected 1 items 

pytest_mp_test.py Process Process-1:
Traceback (most recent call last):
  File "/apps11/bioinfp/Python-2.7.3/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/apps11/bioinfp/Python-2.7.3/lib/python2.7/multiprocessing/process.py", line 114, in run
    self._target(*self._args, **self._kwargs)
  File "/home/bioinfp/jang/hobbyproggorn/gevent-messagepipe/gevent-messagepipe/pytest_mp_test.py", line 9, in child
    assert False
AssertionError: assert False
.

================================ 1 passed in 0.04 seconds ================================

When I manually review the test log, I realize when there is a problem. However, I am wondering if there a neat way to automate exception detection in a child with py.test.

Must I verify the child’s exit code in the parent? Is this the only way?

  • 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-14T10:37:14+00:00Added an answer on June 14, 2026 at 10:37 am

    After some further consideration, I think that just catching the expected exception in the child and checking for the child’s exit state is a very clean and reliable solution, that does not add an additional IPC component to the tests. Example code:

    import multiprocessing
    from py.test import raises
    
    class CustomError(Exception):
        pass
    
    def test_mp_expected_fail():
        p = multiprocessing.Process(target=child_expected_fail)
        p.start()
        p.join()
        assert not p.exitcode
    
    def test_mp_success():
        p = multiprocessing.Process(target=child)
        p.start()
        p.join()
        assert not p.exitcode
    
    def test_mp_unexpected_fail():
        p = multiprocessing.Process(target=child_unexpected_fail)
        p.start()
        p.join()
        assert not p.exitcode
    
    
    def child_expected_fail():
        with raises(CustomError):
            raise CustomError
    
    def child_unexpected_fail():
        raise TypeError
    
    def child():
        pass
    

    Execution:

    $ py.test pytest_mp_test.py 
    ================================== test session starts ===================================
    platform linux2 -- Python 2.7.3 -- pytest-2.3.3
    plugins: cov
    collected 3 items 
    
    pytest_mp_test.py ..F
    
    ======================================== FAILURES ========================================
    ________________________________ test_mp_unexpected_fail _________________________________
    
        def test_mp_unexpected_fail():
            p = multiprocessing.Process(target=child_unexpected_fail)
            p.start()
            p.join()
    >       assert not p.exitcode
    E       assert not 1
    E        +  where 1 = <Process(Process-3, stopped[1])>.exitcode
    
    pytest_mp_test.py:23: AssertionError
    ------------------------------------ Captured stderr -------------------------------------
    Process Process-3:
    Traceback (most recent call last):
      File "/apps11/bioinfp/Python-2.7.3/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
        self.run()
      File "/apps11/bioinfp/Python-2.7.3/lib/python2.7/multiprocessing/process.py", line 114, in run
        self._target(*self._args, **self._kwargs)
      File "/home/bioinfp/jang/hobbyproggorn/gevent-messagepipe/gevent-messagepipe/pytest_mp_test.py", line 31, in child_unexpected_fail
        raise TypeError
    TypeError
    =========================== 1 failed, 2 passed in 0.07 seconds ===========================
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am doing a simple coin flipping experiment for class that involves flipping a
I know there's a lot of other questions out there that deal with this

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.