Merge lp:~wesley-wiedenmeier/curtin/fix-unittests into lp:~curtin-dev/curtin/trunk

Proposed by Wesley Wiedenmeier
Status: Merged
Merged at revision: 416
Proposed branch: lp:~wesley-wiedenmeier/curtin/fix-unittests
Merge into: lp:~curtin-dev/curtin/trunk
Diff against target: 30 lines (+3/-3)
1 file modified
tests/unittests/test_apt_source.py (+3/-3)
To merge this branch: bzr merge lp:~wesley-wiedenmeier/curtin/fix-unittests
Reviewer Review Type Date Requested Status
Christian Ehrhardt  Approve
Ryan Harper (community) Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+302200@code.launchpad.net

Description of the change

Fix the unittests for test_apt_source.
Right now the tests have calls to '.assert_called()' which isn't a valid function in a mock object (although it should be)
Interestingly, this only causes the unittests to fail when running 'make check', but not when running tox.
I think that tox may be skipping these tests completely.

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote :

Agreed. I mentioned this to smoser but probably wasn't clear.

review: Approve
Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

Hi,
I came to about the same conclusion regarding the build error at

https://launchpadlibrarian.net/277356117/buildlog_ubuntu-xenial-amd64.curtin_0.1.0~bzr415-0ubuntu1~ubuntu16.04.1_BUILDING.txt.gz

What I found interesting is, that it doesn't always show up.
On my normal Laptop a make check just runs fine, but I can still reproduce with

./tools/build-deb -S
DEB_BUILD_OPTIONS=parallel=4 sbuild -Adxenial-amd64 curtin_0.1.0~bzr415-0ubuntu1.dsc

While I wonder why it works in a local make check I still agree to the solution as assert_called isn't documented for the mockobject.

review: Approve
Revision history for this message
Scott Moser (smoser) wrote :

Mock is a weird beast. I suspect this is related to one or both of
- http://engineeringblog.yelp.com/2015/02/assert_called_once-threat-or-menace.html
- something is not getting correctly un-patched. I suspect the random failures are order based. Run with -v and compare the other of pass and fail.

On August 8, 2016 2:53:57 AM MDT, ChristianEhrhardt <email address hidden> wrote:
>Review: Approve
>
>Hi,
>I came to about the same conclusion regarding the build error at
>
>https://launchpadlibrarian.net/277356117/buildlog_ubuntu-xenial-amd64.curtin_0.1.0~bzr415-0ubuntu1~ubuntu16.04.1_BUILDING.txt.gz
>
>What I found interesting is, that it doesn't always show up.
>On my normal Laptop a make check just runs fine, but I can still
>reproduce with
>
>./tools/build-deb -S
>DEB_BUILD_OPTIONS=parallel=4 sbuild -Adxenial-amd64
>curtin_0.1.0~bzr415-0ubuntu1.dsc
>
>While I wonder why it works in a local make check I still agree to the
>solution as assert_called isn't documented for the mockobject.
>
>--
>https://code.launchpad.net/~wesley-wiedenmeier/curtin/fix-unittests/+merge/302200
>Your team curtin developers is subscribed to branch lp:curtin.

Revision history for this message
Scott Moser (smoser) wrote :

ok...
so https://bugs.python.org/issue26323 is why you dont see this in tox.
Your (and my) tox environment has mock 2.0. yakkety has 2.0, xenial has 1.3.0.
Thats why I was able to develop this, and even build it locally.

That all said, i'm pulling the change.

Its possible that we should add a tox environment to run unit tests in that sets the versions for each release (similar to what 'trusty-check' does).

Revision history for this message
Scott Moser (smoser) wrote :

the one last thing, is that is concerning is Christian's comment about transient-ness. That would likely indicate there is some issue where one of the tests is not cleaning up correctly and that order of execution of tests matters. I fixed a similar of these issues when a test was modifying one of the globals in apt_source.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/unittests/test_apt_source.py'
2--- tests/unittests/test_apt_source.py 2016-08-04 21:05:09 +0000
3+++ tests/unittests/test_apt_source.py 2016-08-05 23:37:55 +0000
4@@ -932,7 +932,7 @@
5 m_set_sel.return_value = None
6
7 apt_config.apply_debconf_selections({'debconf_selections': data})
8- m_get_inst.assert_called()
9+ self.assertTrue(m_get_inst.called)
10 self.assertEqual(m_set_sel.call_count, 1)
11
12 # assumes called with *args value.
13@@ -979,7 +979,7 @@
14
15 apt_config.apply_debconf_selections({'debconf_selections': data})
16
17- m_get_inst.assert_called()
18+ self.assertTrue(m_get_inst.called)
19 self.assertEqual(m_dpkg_r.call_count, 0)
20
21 @mock.patch("curtin.commands.apt_config.util.subp")
22@@ -996,7 +996,7 @@
23 target=target)
24 # cloud-init is actually the only package we have a cleaner for
25 # so for now, its the only one that should reconfigured
26- m_subp.assert_called()
27+ self.assertTrue(m_subp.called)
28 ci_cleaner.assert_called_with(target)
29 self.assertEqual(m_subp.call_count, 1)
30 found = m_subp.call_args_list[0][0][0]

Subscribers

People subscribed via source and target branches