Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use pytest-forked lib to run test in forked process #5263

Closed
wants to merge 10 commits into from
4 changes: 2 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ jobs:
- name: Test
id: test
run: |
pytest --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' ${{ matrix.test-path }}
pytest --forked --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' ${{ matrix.test-path }}
echo "flag it as jina for codeoverage"
echo "::set-output name=codecov_flag::jina"
timeout-minutes: 30
Expand Down Expand Up @@ -350,7 +350,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test docker compose
run: |
pytest -v -s --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml ./tests/docker_compose/test_*.py
pytest --forked -v -s --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml ./tests/docker_compose/test_*.py
timeout-minutes: 30
- name: Check codecov file
id: check_files
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test docker compose
run: |
pytest -v -s --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml ./tests/docker_compose/test_*.py
pytest --forked -v -s --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml ./tests/docker_compose/test_*.py
timeout-minutes: 30
- name: Check codecov file
id: check_files
Expand Down Expand Up @@ -328,7 +328,7 @@ jobs:
- name: Test
id: test
run: |
pytest --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' ${{ matrix.test-path }}
pytest --forked --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml --timeout=600 -v -s --ignore-glob='tests/integration/hub_usage/dummyhub*' ${{ matrix.test-path }}

echo "flag it as jina for codeoverage"
echo "::set-output name=codecov_flag::jina"
Expand Down
1 change: 1 addition & 0 deletions extra-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,4 @@ jsonschema: cicd
portforward>=0.2.4: cicd
tensorflow>=2.0: cicd
opentelemetry-test-utils>=0.33b0: test
pytest-forked>=1.4.0: test
1 change: 1 addition & 0 deletions jina/resources/extra-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,4 @@ jsonschema: cicd
portforward>=0.2.4: cicd
tensorflow>=2.0: cicd
opentelemetry-test-utils>=0.33b0: test
pytest-forked>=1.4.0: test
25 changes: 0 additions & 25 deletions tests/unit/orchestrate/pods/test_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,28 +192,3 @@ def run_forever(self):
pod = Pod(set_pod_parser().parse_args(['--noblock-on-start']))
pod.start()
pod.close()


@pytest.mark.timeout(4)
def test_close_before_start_slow_enter(monkeypatch):
class SlowFakeRuntime:
def __init__(self, *args, **kwargs):
pass

def __enter__(self):
time.sleep(5.0)

def __exit__(self, exc_type, exc_val, exc_tb):
pass

def run_forever(self):
pass

monkeypatch.setattr(
runtimes,
'get_runtime',
lambda *args, **kwargs: SlowFakeRuntime,
)
pod = Pod(set_pod_parser().parse_args(['--noblock-on-start']))
pod.start()
pod.close()
10 changes: 8 additions & 2 deletions tests/unit/test_yamlparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,19 @@ def test_expand_env():
assert expand_env_var('$PATH-${AA}') != '$PATH-${AA}'


def test_encoder_name_env_replace():
@pytest.fixture
def set_test_encoder_env_var():
os.environ['BE_TEST_NAME'] = 'hello123'
yield
del os.environ['BE_TEST_NAME']


def test_encoder_name_env_replace(set_test_encoder_env_var):
with BaseExecutor.load_config('yaml/test-encoder-env.yml') as be:
assert be.metas.name == 'hello123'


def test_encoder_name_dict_replace():
def test_encoder_name_dict_replace(set_test_encoder_env_var):
d = {'BE_TEST_NAME': 'hello123'}
with BaseExecutor.load_config('yaml/test-encoder-env.yml', context=d) as be:
assert be.metas.name == 'hello123'
Expand Down