ephraimbuddy commented on a change in pull request #16889:
URL: https://github.com/apache/airflow/pull/16889#discussion_r672215533
##########
File path: tests/jobs/test_local_task_job.py
##########
@@ -55,45 +54,35 @@
TEST_DAG_FOLDER = os.environ['AIRFLOW__CORE__DAGS_FOLDER']
-class TestLocalTaskJob(unittest.TestCase):
- def setUp(self):
- db.clear_db_dags()
- db.clear_db_jobs()
- db.clear_db_runs()
- db.clear_db_task_fail()
- patcher = patch('airflow.jobs.base_job.sleep')
- self.addCleanup(patcher.stop)
- self.mock_base_job_sleep = patcher.start()
-
- def tearDown(self) -> None:
+class TestLocalTaskJob:
+ @pytest.fixture(autouse=True)
+ def clean_db_and_set_instance_attrs(self):
db.clear_db_dags()
db.clear_db_jobs()
db.clear_db_runs()
db.clear_db_task_fail()
Review comment:
I do not fully understand the pytest fixtures but from what I have read
so far, if you don't specify the scope, then the default is function scope
which means it's created and cleared at every function run? considering that we
are using it on the class.
I think that if it's not doing 1 & 2 right now that many of the tests on the
class would have failed or what do you think?
##########
File path: tests/jobs/test_local_task_job.py
##########
@@ -55,45 +54,35 @@
TEST_DAG_FOLDER = os.environ['AIRFLOW__CORE__DAGS_FOLDER']
-class TestLocalTaskJob(unittest.TestCase):
- def setUp(self):
- db.clear_db_dags()
- db.clear_db_jobs()
- db.clear_db_runs()
- db.clear_db_task_fail()
- patcher = patch('airflow.jobs.base_job.sleep')
- self.addCleanup(patcher.stop)
- self.mock_base_job_sleep = patcher.start()
-
- def tearDown(self) -> None:
+class TestLocalTaskJob:
+ @pytest.fixture(autouse=True)
+ def clean_db_and_set_instance_attrs(self):
db.clear_db_dags()
db.clear_db_jobs()
db.clear_db_runs()
db.clear_db_task_fail()
Review comment:
Hi @uranusjr, can you take a look again
##########
File path: tests/jobs/test_local_task_job.py
##########
@@ -55,45 +54,35 @@
TEST_DAG_FOLDER = os.environ['AIRFLOW__CORE__DAGS_FOLDER']
-class TestLocalTaskJob(unittest.TestCase):
- def setUp(self):
- db.clear_db_dags()
- db.clear_db_jobs()
- db.clear_db_runs()
- db.clear_db_task_fail()
- patcher = patch('airflow.jobs.base_job.sleep')
- self.addCleanup(patcher.stop)
- self.mock_base_job_sleep = patcher.start()
-
- def tearDown(self) -> None:
+class TestLocalTaskJob:
+ @pytest.fixture(autouse=True)
+ def clean_db_and_set_instance_attrs(self):
db.clear_db_dags()
db.clear_db_jobs()
db.clear_db_runs()
db.clear_db_task_fail()
Review comment:
Thanks @uranusjr, after much search on this, It seems the fixture is
destroyed at the end of each test in the class leaving nothing else to destroy.
I experimented by running the tests in /jobs/ and there was no side effect.
Another option is using autouse=True and not adding on the class, then it would
be used on every test in the module and destroyed at the end of each one.
I think we are on the right path since it runs and destroys on every test
leaving nothing behind. I may be missing something though.
https://docs.pytest.org/en/6.2.x/fixture.html#fixture-scopes
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]