├── pyaction.py ├── test └── test_code.py └── .github └── workflows └── test.yml /pyaction.py: -------------------------------------------------------------------------------- 1 | def add(x, y): 2 | return x + y 3 | 4 | def parse(txt): 5 | res = [] 6 | for item in txt.split(','): 7 | res.append(int(item)) 8 | return res 9 | -------------------------------------------------------------------------------- /test/test_code.py: -------------------------------------------------------------------------------- 1 | import pyaction 2 | 3 | import pytest 4 | 5 | def skipit(name): 6 | return pytest.mark.skipif(name not in dir(pyaction), reason='missing') 7 | 8 | @skipit('parse') 9 | def test_parse(): 10 | txt = '1,2,10' 11 | res = pyaction.parse(txt) 12 | assert res == [1,2,10] 13 | 14 | 15 | @skipit('sub') 16 | def test_sub(): 17 | res = pyaction.sub(1,2) 18 | assert res == -1 19 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: test-python-workflow 4 | 5 | # Controls when the action will run. 6 | on: 7 | # Triggers the workflow on push or pull request events but only for the main branch 8 | push: 9 | branches: [ main ] 10 | pull_request: 11 | branches: [ main ] 12 | 13 | # Allows you to run this workflow manually from the Actions tab 14 | workflow_dispatch: 15 | 16 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 17 | jobs: 18 | # This workflow contains a single job called "run-test" 19 | run-test: 20 | # The type of runner that the job will run on 21 | runs-on: ubuntu-latest 22 | 23 | # Steps represent a sequence of tasks that will be executed as part of the job 24 | steps: 25 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 26 | - uses: actions/checkout@v2 27 | 28 | # Runs a single command using the runners shell 29 | - name: Run a one-line script 30 | run: echo Hello, world! 31 | 32 | # Runs a set of commands using the runners shell 33 | - name: Run a multi-line script 34 | run: | 35 | echo Add other actions to build, 36 | echo test, and deploy your project. 37 | - name: Install deps 38 | run: | 39 | python -m pip install --upgrade pip 40 | pip install pytest 41 | - name: Run tests 42 | run: python -m pytest 43 | --------------------------------------------------------------------------------