Search code examples
pythonpytestattributeerror

Pytest missing approx method


I imported the pytest package in Python 3.5.2 (through Anaconda) and it is missing the approx method. I tried reinstalling pytest through pip, and I still have the same problem. I have many of pytest's other methods, just not approx.

How can I fix this??

      1 import pytest
----> 2 assert 2 == pytest.approx(4.1/2)

AttributeError: module 'pytest' has no attribute 'approx'

Solution

  • Have you tried, from _pytest.python import approx? It works for me. If not, you can search easily with IDE. I am using PyCharm, and I just searched the word approx by double shift and got the location. Simple !!