Skip to content

Second test fails when run with first, but passes when run seperately. #3698

Closed
@RobRoseKnows

Description

@RobRoseKnows

Currently working on a large project and I'm coming across a weird issue when trying to run my pytests. I created a Gist here that recreates the error I'm having.

I don't know if this is deliberate behavior or if I messed something up but when I run the two tests together (either as a file, or as a project wide pytest), the second test fails because it seems to preserve the same copy of an object from the previous test. The class being tested is a wrapper around a class with some non-implemented features with the ones already implemented being tested. The stuff being tested is iterators and subscripting.

This remains the same if I order them differently in the file, also if I change the names. Not too sure what's going on here, so I don't know what else I can tell you.

Here's the output:

$ pytest -v
================================================ test session starts ================================================
platform linux -- Python 3.6.5, pytest-3.6.3, py-1.5.4, pluggy-0.6.0 -- /home/robrose/.pyenv/versions/3.6.5/envs/general/bin/python
cachedir: .pytest_cache
rootdir: /mnt/c/Users/lt-rrose/Dev/debug, inifile:
collected 2 items

test_base.py::test_iter_on_mock_profile PASSED                                                                [ 50%]
test_base.py::test_subscripting_on_mock_profile FAILED                                                        [100%]

===================================================== FAILURES ======================================================
_________________________________________ test_subscripting_on_mock_profile _________________________________________

    @pytest.mark.pytest_style_tests
    def test_subscripting_on_mock_profile():
        mock = ProfileMock([ProviderType.COMPUTE])
        count = 0
        for _ in mock:
            count += 1
>       assert count == 1
E       assert 2 == 1

test_base.py:37: AssertionError
----------------------------------------------- Captured stdout call ------------------------------------------------
ProviderType.COMPUTE
======================================== 1 failed, 1 passed in 0.08 seconds =========================================
$ pytest test_base.py::test_iter_on_mock_profile
================================================ test session starts ================================================
platform linux -- Python 3.6.5, pytest-3.6.3, py-1.5.4, pluggy-0.6.0
rootdir: /mnt/c/Users/lt-rrose/Dev/debug, inifile:
collected 1 item

test_base.py .                                                                                                [100%]

============================================= 1 passed in 0.03 seconds ==============================================
$ pytest test_base.py::test_subscripting_on_mock_profile
================================================ test session starts ================================================
platform linux -- Python 3.6.5, pytest-3.6.3, py-1.5.4, pluggy-0.6.0
rootdir: /mnt/c/Users/lt-rrose/Dev/debug, inifile:
collected 1 item

test_base.py .                                                                                                [100%]

============================================= 1 passed in 0.04 seconds ==============================================

pip list output of the fresh pyenv it's running in:

atomicwrites (1.1.5)
attrs (18.1.0)
more-itertools (4.2.0)
pip (9.0.3)
pluggy (0.6.0)
py (1.5.4)
pytest (3.6.3)
setuptools (39.0.1)
six (1.11.0)

OS is Ubuntu 16.04 on Windows Subsystem for Linux.

Here's a quick checklist in what to include:

  • Include a detailed description of the bug or suggestion
  • pip list of the virtual environment you are using
  • pytest and operating system versions
  • Minimal example if possible

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions