I believe that this error occurs because of the function pandas.testing.assert_frame_equal returns None if frames are equal; if they're unequal it raises AssertionError. Therefore you're actually checking assert None.

So I think you should remove assert operator here and just write

Copytesting.assert_frame_equal(expected, result)

Or write

Copyassert testing.assert_frame_equal(expected, result) is None
Answer from Viacheslav Zhukov on Stack Overflow
🌐
pytest
docs.pytest.org › en › 7.1.x › how-to › assert.html
How to write and report assertions in tests — pytest documentation
pytest_assertrepr_compare(config, op, left, right)[source] Return explanation for comparisons in failing assert expressions. Return None for no custom explanation, otherwise return a list of strings. The strings will be joined by newlines but any newlines in a string will be escaped.
Discussions

Warning about assert None from XFAIL tests
Running pytest master I see warnings from XFAIL tests about asserting None. The warnings suggests to change the assert to assert obj is None but the reason we are asserting None is because the test fails (hence XFAIL). I don't think thes... More on github.com
🌐 github.com
30
January 12, 2019
I have some code in pytest. I am trying to assert the code but none of the asserts are showing and no errors are showing.
Make a simple test case that shows the issue. I looked at the code but the colour scheme hurt my eyes too much to look at it. assert payment_db == None assert x is None is preferred over assert x == None unless you really want the auto type conversion. Also do assert , to be nicer. More on reddit.com
🌐 r/learnpython
3
0
May 29, 2023
python - Is there a pytest method similar to in assertIsNone(x) of unittest - Stack Overflow
I want to check for None value in pytest code. Is there a similar assertIsNone(x) method? I have tried the following but looking for a better way. assert x == None, "Sucess" assert x != None, " Fa... More on stackoverflow.com
🌐 stackoverflow.com
PytestAssertRewriteWarning: asserting the value None, please use "assert is None"
Here is the minimal demo that is working fine on local machine but showing warning while submitting for a handson More on github.com
🌐 github.com
5
November 16, 2019
🌐
GitHub
github.com › pytest-dev › pytest › issues › 3191
give hints when an assertion value is None instead of a boolean · Issue #3191 · pytest-dev/pytest
February 6, 2018 - i believe it would be a nice and simple addition to give a hint in the case that a assertion value was None and this might be a misstake, for clarity None should be tested with x is None or x is not None
Author   RonnyPfannschmidt
🌐
pytest
docs.pytest.org › en › stable › how-to › assert.html
How to write and report assertions in tests - pytest documentation
pytest_assertrepr_compare(config, op, left, right)[source] Return explanation for comparisons in failing assert expressions. Return None for no custom explanation, otherwise return a list of strings. The strings will be joined by newlines but any newlines in a string will be escaped.
🌐
GitHub
github.com › pytest-dev › pytest › issues › 4639
Warning about assert None from XFAIL tests · Issue #4639 · pytest-dev/pytest
January 12, 2019 - The warnings suggests to change the assert to assert obj is None but the reason we are asserting None is because the test fails (hence XFAIL). I don't think these warnings should be emitted from XFAIL tests. ... import pytest @pytest.mark.XFAIL def test_f(): assert g() def g(): # Shouldn't return None but doesn't work properly...
Author   oscarbenjamin
🌐
Reddit
reddit.com › r/learnpython › i have some code in pytest. i am trying to assert the code but none of the asserts are showing and no errors are showing.
r/learnpython on Reddit: I have some code in pytest. I am trying to assert the code but none of the asserts are showing and no errors are showing.
May 29, 2023 -

I am using flask for the code.

I am also not getting any errors or any asserts.

I tried python -m pytest and pytest -q --capture=no. Everything else is working in the files. Why is this not working?

I didn't include the username_form etc but they are just fixtures that return the username etc.

Due to formating issues here is the code

https://paste.pythondiscord.com/obaqahuhok.py

Here is the code.

@pytest.fixture() def yield_selected_columns_PaymentsTest():''' in theCreate the UserTest and the PaymentsTest db. Then yield the PaymentsTest table and finally delete the db. yield does not stop the code when yielded. '''

with app.test_request_context(): # = with app.app_context() except won't work for pytest
    bind_key="testing_app_db"

    def _subfunction(username_form, hashed_password_form, email_form, item_name_form, price_of_donation_form):
        # Create the databases and the database table
        db.create_all(bind_key)
        usertest_db = UserTest(username=username_form, hashed_password=hashed_password_form, email=email_form)
        db.session.add(usertest_db)
        db.session.commit()
        payment_db = PaymentsTest(item_name=item_name_form, price_of_donation=price_of_donation_form)
        db.session.add(payment_db)
        db.session.commit()
        current_email_form = os.environ['TESTING_EMAIL_USERNAME']
        return current_email_form   
    # yield unlike return doesn't stop when called.
    yield _subfunction 
    db.drop_all(bind_key) 

test_functions.py

def test_asserts(yield_selected_columns_PaymentsTest, username_form, hashed_password_form, email_form, item_name_form, price_of_donation_form):

'''
This runs in the /donation route.
If the email have the same value add the foreign key in the payment table.
You will always have a registered account when adding Foreign key. 
I want the foregin key to be added from the db.
'''
assert 1 == 2

email_form = yield_selected_columns_PaymentsTest(username_form, hashed_password_form, 
                email_form, item_name_form, price_of_donation_form)


# if a email exists in the payment table

payment_db = PaymentsTest.query.filter_by(email=email_form).first() 
assert payment_db != None 
assert payment_db == None 

# if email exists in the User table



user_db = UserTest.query.filter_by(email=email_form).first() 
assert user_db == None
assert user_db != None

I based the code on this https://stackoverflow.com/questions/75924656/how-do-i-import-functions-and-classes-into-conftest-py-or-how-do-i-import-fixtu

Thanks

🌐
PyPI
pypi.org › project › pytest-assert-utils
pytest-assert-utils · PyPI
Meta-value which compares True to None or the optionally specified value · >>> from pytest_assert_utils import util >>> util.Optional() == None True >>> util.Optional() is None # this will not work!
      » pip install pytest-assert-utils
    
Published   Apr 14, 2022
Version   0.3.1
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-unittest-assertisnone-function
Python unittest - assertIsNone() function - GeeksforGeeks
July 15, 2025 - assertIsNone() in Python is a unittest library function that is used in unit testing to check that input value is None or not. This function will take two parameters as input and return a boolean value depending upon assert condition.
🌐
Medium
medium.com › codex › pytests-assert-is-not-what-you-think-it-is-ea59dfcb4bfd
Pytest’s assert is not what you think it is. Learn about Python's abstract syntax tree (AST) | CodeX
August 2, 2023 - The AssertionError gives you minimal information. Check the following code; it tells you the two lists are not equal, but doesn’t really tell you which elements of the two lists are different: ... This output is definitely more helpful, but how does pytest make its asserts behave differently?!
🌐
pytest
docs.pytest.org › en › 6.2.x › assert.html
The writing and reporting of assertions in tests — pytest documentation
June 7, 2022 - Rewritten assert statements put introspection information into the assertion failure message. pytest only rewrites test modules directly discovered by its test collection process, so asserts in supporting modules which are not themselves test modules will not be rewritten.
🌐
pytest
docs.pytest.org › en › 4.6.x › reference.html
Reference — pytest documentation
Use pytest.raises as a context manager, which will capture the exception of the given type: ... If the code block does not raise the expected exception (ZeroDivisionError in the example above), or no exception at all, the check will fail instead. You can also use the keyword argument match to assert that the exception matches a text or regex: >>> with raises(ValueError, match='must be 0 or None...
🌐
GitHub
github.com › pytest-dev › pytest › issues › 6203
PytestAssertRewriteWarning: asserting the value None, please use "assert is None" · Issue #6203 · pytest-dev/pytest
November 16, 2019 - PytestAssertRewriteWarning: asserting the value None, please use "assert is None"#6203 · Copy link · KrishnaKantPrajapat · opened · on Nov 16, 2019 · Issue body actions · Here is the minimal demo that is working fine on local machine but showing warning while submitting for a handson ·
Published   Nov 16, 2019
🌐
Codereview
codereview.doctor › features › python › best-practice › use-assert-is-not-none
Use AssertIsNotNone when checking against None best practice | codereview.doctor
assertIsNone and assertIsNotNone provide more helpful failure messages than assertTrue or assertFalse. When performing checks against None it's better to use the correct tool for the job: assertIsNone and assertIsNotNone are provided explicitly for this task.
🌐
Python Tutorial
pythontutorial.net › home › python unit testing › python assertisnone()
Python assertIsNone()
July 9, 2022 - If the expr is None, the test passes. Otherwise, the test will fail. The msg is optional. It’ll be displayed in the test result if the test fails. Let’s take some examples of using the assertIsNone() method.
🌐
JetBrains
youtrack.jetbrains.com › issue › PY-57064 › Warn-pytest-test-cases-returning-not-None
Warn `pytest` test cases returning not `None` : PY-57064
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
pytest
docs.pytest.org › en › 7.1.x › reference › reference.html
API Reference — pytest documentation
Assert that the specified outcomes appear with the respective numbers (0 means it didn’t occur) in the text output from a test run. warnings and deselected are only checked if not None.
🌐
Understanding Data
understandingdata.com › posts › list-of-python-assert-statements-for-unit-tests
The Complete List Of Python Assert Statements - Just Understanding Data
June 28, 2020 - assert 5 != 3 # Success Example assert 5 != 5 # Fail Example --------------------------------------------------------------------------- AssertionError Traceback (most recent call last) <ipython-input-108-de24f583bfdf> in <module> ----> 1 assert 5 != 5 # Fail Example AssertionError:
🌐
Reddit
reddit.com › r/learnpython › in the code below i am getting an error "e assert none != none". i think this is caused by the order of the code. how do i fix the assertion?
r/learnpython on Reddit: In the code below I am getting an error "E assert None != None". I think this is caused by the order of the code. How do I fix the assertion?
February 3, 2024 -

The code starts by running the fixture yield_user_db.

Inside the fixture there is a function. In the function it creates the db then adds some of the columns from the db into the db. Next the code selects a record from the db and returns user_db. Then the sub-function is yielded.

Yield is like a return statement except it doesn't stop the function.

Then the db is deleted.

I realize there is a better way to do this but can I just use 1 fixture yield_user_db to test create_token and verify_token?

Here is an alternative way https://www.youtube.com/watch?v=RLKW7ZMJOf4

app/tests/models.py

from flask_login import UserMixin
from time import time
import jwt
from app import db


class UserTest(UserMixin, db.Model):
    __tablename__ = 'user_test'
    __bind_key__ = "testing_app_db"
    id = db.Column(db.Integer, primary_key=True)
    # unique blocks the same usernames
    # I can't have Nullable=False because it will make me add the columns everytime I add a column in User table
    username = db.Column(db.String(80), unique=True)
    hashed_password = db.Column(db.String(128))
    email = db.Column(db.String(120), unique=True)
    registration_confirmation_email = db.Column(db.Boolean, default=False) 
    # need a better backref name.
    rel_payments = db.relationship('PaymentsTest', backref='profileinfo', lazy=True)
    bind_key = "testing_app_db"

  
  

    def create_token(self, expires_in=600):
            SECRET_KEY = 'temp_secret_key'
            # This Creates the randomly assigned token for 30 min
            return jwt.encode({'create_token': self.id, 'exp': time() + expires_in}, SECRET_KEY, algorithm='HS256')
    
    # use @staticmethod so I don't have to use the self variable. 
    @staticmethod
    def verify_token(token): # token is equal to create_token after called. 
        SECRET_KEY = 'temp_secret_key'
        
        try:
            # jwt.decode() gets the User's id by running the code below
            users_id = jwt.decode(token, SECRET_KEY, algorithms=['HS256'])['reset_password']
        except:
            print('This is an invalid or expired token') 
            return None
        # gives the current user.
        user_db = db.session.execute(db.select(UserTest).filter_by(id=users_id)).scalar_one_or_none()
        user_db = user_db
        return user_db


    def __repr__(self):
        return f"<UserTest('{self.email}')>" 
 


            
class PaymentsTest(db.Model):
    '''
    One to many relationship
    This is the Many relationship. 
    '''
    __bind_key__ = "testing_app_db"
    __tablename__ = 'payments_test'
    id = db.Column(db.Integer, primary_key=True)
    item_name = db.Column(db.String(80)) # what value should this be
    price_of_donation = db.Column(db.Integer)
    # How do I turn email into the foreign key? todo.
    email = db.Column(db.String(120))     
    fk_user_id = db.Column(db.Integer, db.ForeignKey('user_test.id'))
    bind_key = "testing_app_db"
    # what does this do?
    def __repr__(self):
        return f"<PaymentsTest('{self.email}')>" 

tests/functions_and_routes_testing/conftest.py

@pytest.fixture
def username_form():    
    username = 'fkpr[kfkuh'
    return username



from argon2 import PasswordHasher


@pytest.fixture
def hashed_password_form():    
    plaintext_password_form = 'pojkp[kjpj[pj'
    ph = PasswordHasher()
    hashed_password_form  = ph.hash(plaintext_password_form)
    return hashed_password_form


import os 


@pytest.fixture 
def email_form(): 
    email_form = os.environ['TESTING_EMAIL_USERNAME']
    return email_form 


@pytest.fixture
def yield_user_db(): 
    '''
    add the 1 table UserTest 
    '''
    # with app.test_request_context(): # = with app.app_context() except won't work for pytest
    with app.test_request_context(): 
        bind_key="testing_app_db"
        def _subfunction(username_form, hashed_password_form, email_form):
            # Create the databases and the database table
            db.create_all(bind_key)
            usertest_db = UserTest(username=username_form, hashed_password=hashed_password_form, email=email_form)
            db.session.add(usertest_db)
            db.session.commit()
            
            user_db = db.session.execute(db.select(UserTest).filter_by(email=email_form)).scalar_one_or_none()
            return user_db
        # yield unlike return doesn't stop when called.
        yield _subfunction 
        db.drop_all(bind_key) 

tests\functions_and_routes_testing.py

 
from app.tests.models import UserTest
 

def test_token(yield_user_db, username_form, hashed_password_form, email_form):

    user_db = yield_user_db(username_form, hashed_password_form, email_form)
    token = user_db.create_token()
    assert token != None  

    user_db = UserTest.verify_token(token)
    assert user_db != None 
🌐
PyPI
pypi.org › project › pytest-check
pytest-check · PyPI
1 month ago - def test_raises_and_custom_fail_message(): with check.raises(ValueError, msg="custom"): x = 1 / 0 # division by zero error, NOT ValueError assert x == 0 · raises() also accepts an xfail reason. If the raises check fails, the test can be reported as xfailed. If it passes, this does not create an xpass unless the test is already marked with @pytest.mark.xfail.
      » pip install pytest-check
    
Published   Mar 22, 2026
Version   2.8.0