#5755 test_0006_service_show in test_cert_plugin uses global variable wrong
Closed: Fixed None Opened 8 years ago by mbasti.

<not true> At first, tests do not need global variables, there could be instance variables (self.cert and self.newcert) </not true> (read comments)

test_0006_service_show uses global cert and then the cert is used in iteration, what means that cert variable is updated several times without any guarantee which value is the last.

certs_encoded = (base64.b64encode(cert) for cert in res['usercertificate'])

See example bellow:

In [1]: cert = 1

In [2]: def f():
   ...:     global cert
   ...:     l = [cert for cert in range(4)]
   ...:     print cert
   ...:

In [3]: f()
3

In [4]: cert
Out[4]: 3

Now it accidentally works, but any change to test may cause "nice to debug" issues.

This blocks enabling of pylint check global-variable-not-assigned


Please note that pytest creates new instance of class for each testcase, so self.something will not work

master:

  • 929086e Test: dont use global variable for iteration in test_cert_plugin

ipa-4-4:

  • 91e66b9 Test: dont use global variable for iteration in test_cert_plugin

Metadata Update from @mbasti:
- Issue assigned to mbasti
- Issue set to the milestone: FreeIPA 4.4.2

7 years ago

Login to comment on this ticket.

Metadata