Skip to content

Commit

Permalink
using pytest.skip with condition
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiocat93 committed Sep 17, 2024
1 parent 4fb7e1b commit f2aeb6f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/cpu_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
do-the-job:
name: Do the job on the runner
name: Do the job on the cpu
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -17,8 +17,6 @@ jobs:
- {os: ubuntu-latest, architecture: x64, python-version: '3.11'}
- {os: macos-latest, architecture: arm64, python-version: '3.10'}
- {os: macos-latest, architecture: arm64, python-version: '3.11'}
env:
RUN_GPU_TESTS: false
steps:
- name: Hello World
run: echo 'Hello World!'
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/gpu_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ jobs:
name: Run GPU Tests on the runner
needs: start-runner # required to start the main job when the runner is ready
runs-on: ${{ needs.start-runner.outputs.label }} # run the job on the newly created runner
env:
RUN_GPU_TESTS: true
steps:
- name: Hello World
run: echo 'Hello World!'
Expand Down
30 changes: 16 additions & 14 deletions test_math_operations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
import os
import torch
from math_operations import basic_math_operation

def test_add():
Expand All @@ -12,19 +12,21 @@ def test_subtract():
assert basic_math_operation(2, 5, 'subtract') == -3
assert basic_math_operation(0, 0, 'subtract') == 0

if os.getenv("RUN_GPU_TESTS") == "true":
def test_multiply():
assert basic_math_operation(2, 3, 'multiply') == 6
assert basic_math_operation(-2, 3, 'multiply') == -6
assert basic_math_operation(0, 5, 'multiply') == 0
@pytest.mark.skipif(not torch.cuda.is_available(), reason="GPU is not available")
def test_multiply():
assert basic_math_operation(2, 3, 'multiply') == 6
assert basic_math_operation(-2, 3, 'multiply') == -6
assert basic_math_operation(0, 5, 'multiply') == 0

def test_divide():
assert basic_math_operation(6, 3, 'divide') == 2
assert basic_math_operation(7, 2, 'divide') == 3.5
@pytest.mark.skipif(not torch.cuda.is_available(), reason="GPU is not available")
def test_divide():
assert basic_math_operation(6, 3, 'divide') == 2
assert basic_math_operation(7, 2, 'divide') == 3.5

with pytest.raises(ValueError):
basic_math_operation(6, 0, 'divide')
with pytest.raises(ValueError):
basic_math_operation(6, 0, 'divide')

def test_invalid_operation():
with pytest.raises(ValueError):
basic_math_operation(2, 3, 'modulus')
@pytest.mark.skipif(not torch.cuda.is_available(), reason="GPU is not available")
def test_invalid_operation():
with pytest.raises(ValueError):
basic_math_operation(2, 3, 'modulus')

0 comments on commit f2aeb6f

Please sign in to comment.