import pytest import numpy as np import pandas as pd # This would be added to conftest.py @pytest.fixture(autouse=True) def stop_chaining(): pd.set_option("chained_assignment", "raise") class TestExample(object): def test_should_fail(self): df = pd.DataFrame( {'a' : ['one', 'one', 'two', 'three', 'two', 'one', 'six'], 'c' : np.arange(7) } ) # Chained assignment, should raise. df['c'][df.a.str.startswith('o')] = 42