-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[pytest] | ||
log_cli = true | ||
log_cli_level = INFO | ||
log_cli_format = %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s) | ||
log_cli_date_format = %Y-%m-%d %H:%M:%S |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pytest>=7.4.4 | ||
pytest-celery[celery]@git+https://github.com/celery/pytest-celery.git | ||
pytest-xdist>=3.5.0 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from types import ModuleType | ||
|
||
import pytest | ||
|
||
from pytest_celery import CeleryTestWorker | ||
|
||
|
||
class MyWorker(CeleryTestWorker): | ||
|
||
def myfunc(self) -> bool: | ||
exit_code, output = self.container.exec_run( | ||
'python -c "from utils import myfunc; print(myfunc())"', | ||
) | ||
if exit_code != 0: | ||
raise RuntimeError(f"Error: {output}") | ||
output = output.decode("utf-8") | ||
return output.strip() | ||
|
||
|
||
@pytest.fixture | ||
def default_worker_cls() -> type[CeleryTestWorker]: | ||
return MyWorker | ||
|
||
|
||
@pytest.fixture | ||
def default_worker_utils_module() -> ModuleType: | ||
from tests import myutils | ||
|
||
return myutils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from pytest_celery.vendors.worker.content.utils import get_running_processes_info # noqa | ||
|
||
|
||
def myfunc(): | ||
return "foo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from pytest_celery import CeleryTestSetup | ||
from tests.conftest import MyWorker | ||
|
||
|
||
def test_myfunc_in_worker(celery_worker: MyWorker): | ||
assert celery_worker.myfunc() == "foo" | ||
assert celery_worker.get_running_processes_info() | ||
|
||
|
||
def test_myfunc_in_setup_worker(celery_setup: CeleryTestSetup): | ||
celery_worker: MyWorker = celery_setup.worker | ||
assert celery_worker.myfunc() == "foo" | ||
assert celery_worker.get_running_processes_info() |