Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing: Mock object will always return True! #5812

Closed
wxtim opened this issue Nov 3, 2023 · 0 comments · Fixed by #5832
Closed

Testing: Mock object will always return True! #5812

wxtim opened this issue Nov 3, 2023 · 0 comments · Fixed by #5832
Assignees
Labels
could be better Not exactly a bug, but not ideal. small
Milestone

Comments

@wxtim
Copy link
Member

wxtim commented Nov 3, 2023

Investigate replacing tests/unit/test_indep_task_queues.py with an integration test.

Description

The code at

assert r.state.reset.called_with(TASK_STATUS_PREPARING)
does not work as desired: One may add a line such as

        assert r.state.garbage_method.called_with(TASK_STATUS_PREPARING)

Which will also pass!

As explained in python/cpython#100690 this is because up to Python 3.11

(Pdb) type(r.state.reset.called_with)
<class 'unittest.mock.Mock'>

which will return true, and not as the reader would expect, test the truth of that method having been called.

At Python 3.12 additional checks have been added, preventing this issue, but breaking the tests.

Investigate

Check whether the method under test should be called. I don't think that the state of the task should change - it should be waiting before and after so I suspect that this test shouldn't pass, and just needs correcting. We might want to test the task proxy's is_queued flag though.

It might be more sensible to run this as an integration test rather than a unit test.

@wxtim wxtim added bug Something is wrong :( question Flag this as a question for the next Cylc project meeting. labels Nov 3, 2023
@wxtim wxtim self-assigned this Nov 3, 2023
@wxtim wxtim added this to the cylc-8.3.0 milestone Nov 3, 2023
@MetRonnie MetRonnie modified the milestones: cylc-8.3.0, cylc-8.2.4 Nov 3, 2023
oliver-sanders pushed a commit that referenced this issue Nov 13, 2023
* add generic Python 3 (i.e. A bleeding edge version) to tests
* remove report timings from Python 3.12
* fix flake8 issues
* Commented out broken test lines (see #5812)
* replace smtpd with aiosmtpd in the test_header file
* fix tests

---------

Co-authored-by: Ronnie Dutta <61982285+MetRonnie@users.noreply.github.com>
@MetRonnie MetRonnie assigned MetRonnie and unassigned wxtim Nov 21, 2023
@MetRonnie MetRonnie linked a pull request Nov 21, 2023 that will close this issue
8 tasks
@MetRonnie MetRonnie added small could be better Not exactly a bug, but not ideal. and removed bug Something is wrong :( question Flag this as a question for the next Cylc project meeting. labels Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
could be better Not exactly a bug, but not ideal. small
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants