← Back to DAGDA | Support | Source: https://github.com/pytest-dev/pytest/issues/2796
Skip to content

Possible bug in pytest --doctest comparison #2796

Closed

Description

@mirca

In Python:

>>> -0.0 == 0.0
True

Whereas while running pytest --doctest-modules (version 3.0.7):

Expected:
    0.0
Got:
    -0.0

Activity

  1. nicoddemus commented on Sep 25, 2017

    @nicoddemus
    Member

    Thanks @mirca.

    I can't reproduce the problem though, either on master or in version 3.0.7. Could you please test using the latest version and provide a minimal reproducible example if the error still happens? Thanks!

  2. added
    plugin: doctests
    status: needs information
    type: bug
    on Sep 25, 2017
  3. mirca commented on Sep 26, 2017

    @mirca
    Author

    I tested with version 3.2.1 as well and got the same error:

    ➜ pytest --doctest-modules test.py
    ================================= test session starts ==================================
    platform darwin -- Python 3.6.2, pytest-3.2.1, py-1.4.34, pluggy-0.4.0
    rootdir: /Users/jvmirca, inifile:
    plugins: pep8-1.0.6, cov-2.5.1
    collected 1 item
    
    test.py F
    
    ======================================= FAILURES =======================================
    ____________________________________ [doctest] test ____________________________________
    001
    002 >>> import numpy as np
    003 >>> - np.log(1)
    Expected:
        0.0
    Got:
        -0.0
    

    where test.py is:

    """
    >>> import numpy as np
    >>> - np.log(1)
    0.0
    """
    
  4. nicoddemus commented on Sep 26, 2017

    @nicoddemus
    Member

    Thanks @mirca for the reproducible example.

    I can reproduce the same error in pytest and also using the standard library's doctest:

    """
    >>> import numpy as np
    >>> - np.log(1)
    0.0
    """
    
    if __name__ == '__main__':
        import doctest
        doctest.testmod()
    $python .tmp\test_doctest.py
    **********************************************************************
    File ".tmp\test_doctest.py", line 3, in __main__
    Failed example:
        - np.log(1)
    Expected:
        0.0
    Got:
        -0.0
    **********************************************************************
    1 items had failures:
       1 of   2 in __main__
    ***Test Failed*** 1 failures.
    

    pytest uses the standard doctest for test collection and comparison, so it is actually a bug in python's doctest module. I suggest to report this problem in Python's issue tracker.

    pytest can't really do anything in this case, so I'm closing this.

  5. mirca commented on Sep 26, 2017

    @mirca
    Author

    @nicoddemus Thanks for following up on this.

  6. nicoddemus commented on Sep 26, 2017

    @nicoddemus
    Member

    No problem 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: doctestsstatus: needs informationtype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions