Skip to content

test: replace unittest.skip decorators with pytest equivalents#6570

Merged
blackboxsw merged 2 commits into
canonical:mainfrom
blackboxsw:convert-unittest-skip-to-pytest
Nov 11, 2025
Merged

test: replace unittest.skip decorators with pytest equivalents#6570
blackboxsw merged 2 commits into
canonical:mainfrom
blackboxsw:convert-unittest-skip-to-pytest

Conversation

@blackboxsw
Copy link
Copy Markdown
Collaborator

@blackboxsw blackboxsw commented Nov 11, 2025

Proposed Commit Message

See commit descriptions

  • test: fix bug in tmp_path used as a callable for path join operation

  • test: replace unittest.skip decoartors with pytest equivalents

    Issue: When running tests with pytest, unittest-style skip decorators raise unittest.case.SkipTest exceptions which pytest interprets as FAILED rather than SKIPPED on non-unittest.TestCase classes. This caused tests to incorrectly show as failures.

Replace unittest.skipIf/skip with pytest.mark.skipif/skip to prevent SkipTest exceptions from being treated as test failures.

Fixes GH-6569

Additional Context

CI build failure reproducing this issue

Test Steps

In a questing environment:  `tox -e py3 `

Merge type

  • Squash merge using "Proposed Commit Message"
  • Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

@blackboxsw blackboxsw requested a review from Copilot November 11, 2025 17:29
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses a test framework compatibility issue where unittest-style skip decorators (unittest.skipIf, unittest.skip) were incorrectly marking tests as FAILED instead of SKIPPED when running non-unittest.TestCase classes with pytest. The changes replace all unittest skip decorators with their pytest equivalents (pytest.mark.skipif, pytest.mark.skip).

Key changes:

  • Replaced unittest.skipIf and unittest.skip decorators with pytest.mark.skipif and pytest.mark.skip throughout the test suite
  • Updated helper functions that returned unittest skip decorators to return pytest skip markers instead
  • Added reason parameter to all skip decorators for better test output clarity

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/unittests/helpers.py Removed skipIf alias to unittest.skipIf and updated all helper functions to return pytest.mark.skipif instead
tests/unittests/test_util.py Replaced unittest.skipIf decorators with pytest.mark.skipif on test classes and methods, removed import of skipIf helper
tests/unittests/sources/test_smartos.py Replaced skipIf decorator with pytest.mark.skipif, removed import of skipIf helper
tests/unittests/sources/test_azure_helper.py Replaced unittest.skip decorators with pytest.mark.skip
tests/unittests/config/test_cc_chef.py Replaced skipIf decorators with pytest.mark.skipif, removed import of skipIf helper
tests/unittests/test_templating.py Fixed unrelated bug where tmp_path was being called as a function instead of using path concatenation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@blackboxsw blackboxsw force-pushed the convert-unittest-skip-to-pytest branch from b906954 to db964bd Compare November 11, 2025 17:31
Issue: When running tests with pytest, unittest-style skip decorators
raise unittest.case.SkipTest exceptions which pytest interprets as
FAILED rather than SKIPPED on non-unittest.TestCase classes. This
caused tests to incorrectly show as failures.

Replace unittest.skipIf/skip with pytest.mark.skipif/skip to prevent
SkipTest exceptions from being treated as test failures.

Fixes canonicalGH-6569
@blackboxsw blackboxsw force-pushed the convert-unittest-skip-to-pytest branch from db964bd to 97b5f81 Compare November 11, 2025 17:33
@blackboxsw blackboxsw force-pushed the convert-unittest-skip-to-pytest branch from 97b5f81 to 689cb65 Compare November 11, 2025 17:35
Copy link
Copy Markdown
Contributor

@cjp256 cjp256 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Cade was just working on the azure tests to ensure they run - can follow after this PR merges.

@blackboxsw blackboxsw merged commit f63bbbf into canonical:main Nov 11, 2025
21 checks passed
@blackboxsw
Copy link
Copy Markdown
Collaborator Author

Thanks @cjp256 since these test changes affect a few PRs in flight, let's merge this so affected developers can rebase and pull in the 'fixes'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

raise unittest.SkipTest being treated as failures by pytest

3 participants