Body
All tests for Apache Airflow are run using pytest. We have about 80 tests modules which still use unittests runner for pytest , initial plan was "convert all unit tests to standard "asserts" semi-automatically, but this will be done later in Airflow 2.0 development phase. That will include setUp/tearDown/context managers and decorators.", see: Writing Unit Tests
Personally I do not have a free time to complete this tasks, if someone would like to work on one (or many) parts of this Task just let us know in comments or create a PR with reference to this Issue.
For keep in track remaining tasks for migration to "native" pytest runner I split it by separate phases
Phase 1: Migration unittests to pytest
- Replace unittests by pytest
- Replace
@parameterized.expand by @pytest.mark.parametrize
Example how it done previously: https://github.com/apache/airflow/pulls?q=is%3Apr+migrate+tests+pytest+is%3Aclosed+
Always
CLI
Other
Providers
- Google (GCP)
- Amazon (AWS)
- Apache Flink
Phase 2: Ban unittests runner
It should be done after Phase 1.
This also include remove parametrized package, all features already exists in pytest core, see: How to parametrize fixtures and test functions
Some useful stuff
I use this command to find any remaining usage of unittests.TestCase and parametrized
# All modules which potentially use unittests.TestCase
❯ grep -rl 'TestCase' ./tests | sort | uniq -c | sort -nr
# All modules which potentially use parameterized
❯ grep -rl 'from parameterized' ./tests | sort | uniq -c | sort -nr
# List of providers which potentially use unittests.TestCase
❯ grep -rl 'TestCase' tests/providers/ | cut -d"/" -f4 | sort | uniq -c | sort -nr
Committer
Body
All tests for Apache Airflow are run using
pytest. We have about 80 tests modules which still useunittestsrunner for pytest , initial plan was "convert all unit tests to standard "asserts" semi-automatically, but this will be done later in Airflow 2.0 development phase. That will include setUp/tearDown/context managers and decorators.", see: Writing Unit TestsPersonally I do not have a free time to complete this tasks, if someone would like to work on one (or many) parts of this Task just let us know in comments or create a PR with reference to this Issue.
For keep in track remaining tasks for migration to "native" pytest runner I split it by separate phases
Phase 1: Migration unittests to pytest
@parameterized.expandby@pytest.mark.parametrizeExample how it done previously: https://github.com/apache/airflow/pulls?q=is%3Apr+migrate+tests+pytest+is%3Aclosed+
Always
tests/alwaysto pytest migrated some part of test always to pytest #29375CLI
tests/clito pytest migrating from unittest to pytest tests cli file #29354Other
tests/operatorsto pytest Migrated operators tests topytest#29377@parameterized.expandby@pytest.mark.parametrizeintests/callbacksmigrated callback tests to pytest #29373Providers
tests/providers/google/cloud/operatorsto pytest Migrate tests in google/cloud/operators from unittest to pytest #29775tests/providers/google/cloud/transfersto pytest migrated tests/providers/google/cloud/transfers to pytest #29757tests/providers/google/cloud/sensorsto pytest Migrate tests in google/cloud/sensors from unittest to pytest #29642tests/providers/amazon/awsto pytest Migrated tests/providers/amazon/aws to pytest #29758tests/providers/apache/flinkto pytest migrated all providers/apache/flink to pytest #29604Phase 2: Ban unittests runner
It should be done after Phase 1.
This also include remove
parametrizedpackage, all features already exists in pytest core, see: How to parametrize fixtures and test functionstests/test_utils, as far as I know right now only one place where we use it. Remove unittests.TestCase from tests/test_utils #30685 (review)unittest.TestCaseit could be done by different ways:-p no:unittestinpytest.iniadopts section, this step only disable discovering classes based onunittests.TestCase.Some useful stuff
I use this command to find any remaining usage of
unittests.TestCaseandparametrizedCommitter