Skip or Disable Tests in Pytest

And if you’re working with optional dependencies, pytest skipif is even more powerful! You can use it to check if a library (like Pandas) is installed before running a test."

import pytest
import importlib.util

@pytest.mark.skipif(not importlib.util.find_spec("pandas"), reason="Requires the Pandas library")
def test_pandas_function():
    import pandas
    pass  # Only runs if Pandas is installed

Now, your test suite won’t fail unnecessarily—pytest will only run tests when the required dependencies are available. pytest skip keeps your testing workflow smooth!