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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:08:33+00:00 2026-06-15T20:08:33+00:00

Define the files python_assert.py and cython_assert.pyx to be identical, each containing a simple function

  • 0

Define the files python_assert.py and cython_assert.pyx to be identical, each containing a simple function that raises AssertionError:

def raise_assertionerror():
    assert False

I would expect both of the following tests to succeed under pytest:

import pytest

import pyximport
pyximport.install()

from python_assert import raise_assertionerror as python_assert
from cython_assert import raise_assertionerror as cython_assert

def test_assertion():
    with pytest.raises(AssertionError):
        python_assert()

def test_cython_assertion():
    with pytest.raises(AssertionError):
        cython_assert()

However, the cython test fails:

===================================== FAILURES ======================================
_______________________________ test_cython_assertion _______________________________

    def test_cython_assertion():
        with pytest.raises(AssertionError):
>           cython_assert()

test_pytest_assertion.py:15: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

>   assert False
E   AssertionError

cython_assert.pyx:2: AssertionError
======================== 1 failed, 1 passed in 0.61 seconds =========================

This seems to be a problem with pytest because the equivalent unittest succeeds:

import unittest

import pyximport
pyximport.install()

from python_assert import raise_assertionerror as python_assert
from cython_assert import raise_assertionerror as cython_assert

class MyTestCase(unittest.TestCase):
    def test_cython(self):
        self.assertRaises(AssertionError, cython_assert)

    def test_python(self):
        self.assertRaises(AssertionError, python_assert)

if __name__ == "__main__":
    unittest.main()

Further, the pytest test succeeds if we call pytest.raises(Exception) instead of pytest.raises(AssertionError).

Any idea what is wrong?

  • 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-15T20:08:34+00:00Added an answer on June 15, 2026 at 8:08 pm

    This has been recognized as a bug in pytest and resolved.

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

Sidebar

Related Questions

I have these two simple files that define a C++ class with a tryME
I am loading some template files into my application using require.js like so: define(function(require)
I have 10 XML files containing several Objects. The XML files define ACTIONS on
I'm using the Python execfile() function as a simple-but-flexible way of handling configuration files
I have created two files: tunables.h #ifndef TUNABLES_H #define TUNABLES_H void tunables_load_conservative(); void tunables_load_aggressive();
I'd like to define a union, for reading special kind of binary files. The
Ok so I've got 3 files: definitions.h which contains #ifndef COMPLEX_H #define COMPLEX_H class
I have 4 files: shared.h main.cpp something.h something.cpp shared.h: #ifndef SHARED_H #define SHARED_H int*
Lets say i have at least two lua script files. test1.lua test2.lua both define
I need to define a Wix file component that may not exist in certain

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.