Taragolis opened a new issue, #29305:
URL: https://github.com/apache/airflow/issues/29305

   ### Body
   
   All tests for Apache Airflow are run using 
[`pytest`](http://doc.pytest.org/en/latest/). We have about 80 tests modules 
which still use [`unittests`](https://docs.python.org/3/library/unittest.html) 
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](https://github.com/apache/airflow/blob/main/TESTING.rst#id4)
   
   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
   ---
   
   1. Replace unittests by pytest
   2. 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**
   - [ ] Migrate remaining `tests/always` to pytest
   
   **CLI**
   - [ ] Migrate remaining `tests/cli` to pytest
   
   **Other**
   - [ ] Migrate remaining `tests/operators` to pytest
   - [ ] Replace `@parameterized.expand` by `@pytest.mark.parametrize` in 
`tests/callbacks`
   
   **Providers**
   - Google (GCP)
      + [ ] Migrate remaining GCP operators tests 
`tests/providers/google/cloud/operators` to pytest
      + [ ] Migrate remaining GCP transfers operators tests 
`tests/providers/google/cloud/transfers` to pytest
      + [ ] Migrate remaining GCP sensors tests 
`tests/providers/google/cloud/sensors` to pytest
   - Amazon (AWS)
      +  [ ] Migrate remaining AWS tests `tests/providers/amazon/aws` to pytest
   - Apache Flink
     + [ ]  Migrate Apache Flink tests `tests/providers/apache/flink` to pytest
   
   
   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](https://docs.pytest.org/en/latest/how-to/parametrize.html#how-to-parametrize-fixtures-and-test-functions)
   
   - [ ] Remove all unittests.TestCase usage in `tests/test_utils`, as far as I 
know right now [only one 
place](https://github.com/Taragolis/airflow/blob/ce677862be4a7de777208ba9ba9e62bcd0415393/tests/test_utils/asserts.py#L38)
 where we use it. 
   - [ ] Ban inheritance from `unittest.TestCase` it could be done by different 
ways:
      + Create collector hook which raise an error if detected 
unittests.TestCase, the opposite how builtin pytest plugin works, see: 
[unittest.py::pytest_pycollect_makeitem](https://github.com/pytest-dev/pytest/blob/4a46ee8bc957b06265c016cc837862447dde79d2/src/_pytest/unittest.py#L44-L57)
      + Develop pre-commit hook
   - [ ] Disable builtin unittests plugin by add `-p no:unittest` in 
[`pytest.ini` adopts 
section](https://github.com/apache/airflow/blob/d80b583db07197c8c3d0549a805e83ceaaf10d52/pytest.ini#L19-L26),
 this step only disable discovering classes based on `unittests.TestCase`.
   
   Some useful stuff
   ---
   
   I use this command to find any remaining usage of `unittests.TestCase` and 
`parametrized`
   
   ```console
   
   # 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
   
   - [X] I acknowledge that I am a maintainer/committer of the Apache Airflow 
project.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to