File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Python CI
2+
3+ on :
4+ push :
5+ branches : [ main ]
6+ pull_request :
7+ branches : [ main ]
8+
9+ jobs :
10+ test :
11+ runs-on : ubuntu-latest
12+
13+ steps :
14+ - uses : actions/checkout@v3
15+
16+ - name : Set up Python
17+ uses : actions/setup-python@v4
18+ with :
19+ python-version : ' 3.9'
20+
21+ - name : Install dependencies
22+ run : |
23+ python -m pip install --upgrade pip
24+ pip install pytest
25+
26+ - name : Run tests
27+ run : |
28+ python -m pytest tests/ -v
Original file line number Diff line number Diff line change 11# test-action
2+
23Test Github Actions
4+
5+ ## Project Structure
6+
7+ This is a simple Python project with a Hello World function and associated tests to demonstrate GitHub Actions CI/CD workflow.
8+
9+ ## Files
10+
11+ - ` helloworld.py ` : Contains simple greeting functions
12+ - ` tests/test_helloworld.py ` : Pytest tests for the greeting functions
13+ - ` .github/workflows/python-ci.yml ` : GitHub Actions workflow for running tests
14+
15+ ## Functions
16+
17+ - ` hello_world() ` : Returns "Hello, World!"
18+ - ` greet(name) ` : Returns a personalized greeting "Hello, {name}!"
19+
20+ ## Running Tests Locally
21+
22+ To run the tests locally:
23+
24+ 1 . Install pytest:
25+ ```
26+ pip install pytest
27+ ```
28+
29+ 2 . Run the tests:
30+ ```
31+ python -m pytest tests/ -v
32+ ```
33+
34+ ## GitHub Actions
35+
36+ This repository uses GitHub Actions to automatically run tests on every push and pull request to the main branch.
Original file line number Diff line number Diff line change 1+ def hello_world ():
2+ """Return the classic 'Hello, World!' string."""
3+ return "Hello, World!"
4+
5+
6+ def greet (name ):
7+ """Return a personalized greeting."""
8+ return f"Hello, { name } !"
9+
10+
11+ if __name__ == "__main__" :
12+ print (hello_world ())
Original file line number Diff line number Diff line change 1+ import pytest
2+ from helloworld import hello_world , greet
3+
4+
5+ def test_hello_world ():
6+ """Test the hello_world function returns the correct string."""
7+ assert hello_world () == "Hello, World!"
8+
9+
10+ def test_greet ():
11+ """Test the greet function returns a personalized greeting."""
12+ assert greet ("Alice" ) == "Hello, Alice!"
13+ assert greet ("Bob" ) == "Hello, Bob!"
14+
15+
16+ def test_greet_empty_string ():
17+ """Test the greet function with an empty string."""
18+ assert greet ("" ) == "Hello, !"
You can’t perform that action at this time.
0 commit comments