cloud-init icon indicating copy to clipboard operation
cloud-init copied to clipboard

Pytestify tests with unittest.TestCase

Open aciba90 opened this issue 4 months ago • 14 comments

Convert tests using unittests.TestCase and the cloud-init custom one to pytest.

  • [x] tests/unittests/test_pathprefix2dict.py
  • [ ] tests/unittests/config/test_cc_rsyslog.py
  • [ ] tests/unittests/config/test_cc_power_state_change.py
  • [x] tests/unittests/config/test_apt_conf_v1.py
  • [x] tests/unittests/config/test_schema.py
  • [ ] tests/unittests/config/test_cc_growpart.py
  • [x] tests/unittests/config/test_cc_spacewalk.py
  • [ ] tests/unittests/config/test_cc_ca_certs.py
  • [x] tests/unittests/config/test_cc_mcollective.py
  • [x] tests/unittests/sources/test_openstack.py
  • [x] tests/unittests/sources/test_common.py
  • [ ] tests/unittests/test_util.py
  • [x] tests/unittests/distros/test_resolv.py
  • [x] tests/unittests/distros/test_user_data_normalize.py
  • [x] tests/unittests/distros/test_hosts.py
  • [x] tests/unittests/distros/test_hostname.py
  • [x] tests/unittests/distros/test_ifconfig.py
  • [x] tests/unittests/distros/test_sysconfig.py
  • [x] tests/unittests/distros/test_alpine.py
  • [ ] tests/unittests/helpers.py
  • [x] tests/unittests/test_registry.py
  • [x] tests/unittests/test__init__.py
  • [x] tests/unittests/reporting/test_reporting.py
  • [x] tests/unittests/test_data.py

aciba90 avatar Aug 27 '25 13:08 aciba90

Hi team, I’m looking at the PR #6427 to convert tests using unittest.TestCase (and the cloud-init custom test classes) to pytest. I want to clarify a few things before I start:

Should all the listed test files under tests/unittests/ be fully converted to pytest, including config, distros, and helpers?

For the custom cloud-init test classes, do you want them fully rewritten with pytest fixtures, or just drop the base class and convert asserts?

Any specific CI/test requirements to keep in mind while converting? Once I get confirmation, I can start the conversion and open a commit/PR with all changes. Thanks!

Aamir017 avatar Aug 27 '25 18:08 Aamir017

Hello, thanks for the interest in making cloud-init better.

It is encouraged to accomplish this issue by small PRs, to ease the work and the review, so please do limit the scope of your PRs.

About fixtures, I would say use them when it makes sense. General testing guidelines: https://cloudinit.readthedocs.io/en/latest/development/testing.html.

Do not hesitate to ask any question. Thanks again!

aciba90 avatar Aug 28 '25 07:08 aciba90

Thanks for the clarification! To confirm, I’ll start by converting just a small set of files (e.g. 1–2 test files) to pytest and open a PR for review. Once that’s merged, I’ll continue in small batches until the full list from #6427 is covered.

I’ll use fixtures only where it makes sense, and I’ll follow the testing guidelines you shared.

Does that workflow sound good to you?

Aamir017 avatar Aug 28 '25 08:08 Aamir017

https://github.com/canonical/cloud-init/pull/6433

aciba90 avatar Aug 29 '25 08:08 aciba90

Hi @aciba90. Can I possibly join in to handle some of these test conversions? I'm a new contributor

chijioke-ibekwe avatar Aug 29 '25 09:08 chijioke-ibekwe

Hi! I’d like to work on this issue for Hacktoberfest by pytestifying the following files:

I’ll keep the scope limited to these two files for this PR.

lyushher avatar Sep 25 '25 11:09 lyushher

Hi @aciba90 . I have created a PR for migration of tests/unittests/distros/test_resolv.py to pytest. can you please review it.

csemanish12 avatar Oct 11 '25 05:10 csemanish12

Hi @aciba90 I have created a PR for migration of tests/unittests/distros/test_sysconfig.py to pytest. can you please review it.

csemanish12 avatar Oct 14 '25 02:10 csemanish12

Hi @aciba90 I have created a PR for migration of tests/unittests/distros/test_hostname.py to pytest. can you please review it.

Pneha1234 avatar Oct 14 '25 05:10 Pneha1234

Hi @aciba90 I have created a PR for migration of tests/unittests/sources/test_common.py to pytest. can you please review it.

Pneha1234 avatar Oct 14 '25 06:10 Pneha1234

Hi @aciba90 I have created a PR for migration of tests/unittests/config/test_cc_spacewalk.py to pytest. can you please review it.

Pneha1234 avatar Oct 17 '25 03:10 Pneha1234

Nice work hacktoberfest contributors. Only a few items left on this mega tech-debt task. Great contributions so far.

blackboxsw avatar Oct 21 '25 18:10 blackboxsw

Hello, I would like to work on this issue if possible.

MoeSalah1999 avatar Dec 11 '25 18:12 MoeSalah1999

Hello, I would like to work on this issue if possible.

@MoeSalah1999 Hey o/ feel free, please do.

holmanb avatar Dec 11 '25 18:12 holmanb