Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

66%
+2 −0
Q&A How to use Python/pytest to organize unit and system tests?

I have a big system which I want to test using Python scripts: using pytest or any other infrastructure. Some of my tests are of the "pass/fail" type; pytest has great support for these, like coll...

1 answer  ·  posted 11mo ago by anatolyg‭  ·  last activity 11mo ago by Karl Knechtel‭

Question python unit-testing pytest
#2: Post edited by user avatar anatolyg‭ · 2025-10-29T15:19:29Z (11 months ago)
  • I have a big system which I want to test using Python scripts: using `pytest` or any other infrastructure.
  • Some of my tests are of the "pass/fail" type; `pytest` has great support for these, like collecting, executing, summarizing, etc. Let's call them unit tests.
  • However, I have different tests, which produce some data about the system, like speed, quality, etc. I want to run these tests manually and examine the results (which are in csv or HTML format). Let's call them system tests.
  • Currently, I use shell-scripts for them. That means that any common part between these and unit tests has two versions: one written in shell language and another in Python.
  • How could I organize all my tests using Python?
  • I run my shell-scripts like this:
  • ```
  • test/speed_test_1/run.sh
  • test/speed_test_2/run.sh
  • test/quality_test/run.sh
  • ```
  • Naively, I'd like to rewrite them in Python and run like this:
  • ```
  • test/speed_test_1/run.py
  • test/speed_test_2/run_this.py
  • test/speed_test_2/run_that.py
  • test/quality_test/run.py
  • ```
  • However, running Python scripts in a subdirectory is not recommended because of problems with imports. That is — where would I put `pytest` fixtures and how would the `run` scripts access them? Not sure there is a good solution for that.
  • Could I use `pytest` to run my system tests? I imagine I'd need to change my command lines to something like this:
  • ```
  • python -m pytest -k speed_test_1
  • python -m pytest -k speed_test_2_this
  • python -m pytest -k speed_test_2_that
  • python -m pytest -k quality_test
  • ```
  • which looks ugly (e.g. there is no tab-completion for test names). And in addition, does pytest really support tests which have output other than pass/fail? I imagine there is something equally ugly I need to do to access my generated reports.
  • Is there a way I could use `pytest` or just any Python code to write system tests which could be invoked manually using shell-like syntax?
  • I have a big system which I want to test using Python scripts: using `pytest` or any other infrastructure.
  • Some of my tests are of the "pass/fail" type; `pytest` has great support for these, like collecting, executing, summarizing, etc. Let's call them unit tests.
  • However, I have different tests, which produce some data about the system, like speed, quality, etc. I want to run these tests manually and examine the results (which are in csv or HTML format). Let's call them system tests.
  • Currently, I use shell-scripts for them. That means that any common part between these and unit tests has two versions: one written in shell language and another in Python.
  • How could I organize all my tests using Python?
  • I run my shell-scripts like this:
  • ```
  • test/speed_test_1/run.sh
  • test/speed_test_2/run_this.sh
  • test/speed_test_2/run_that.sh
  • test/quality_test/run.sh
  • ```
  • Naively, I'd like to rewrite them in Python and run like this:
  • ```
  • test/speed_test_1/run.py
  • test/speed_test_2/run_this.py
  • test/speed_test_2/run_that.py
  • test/quality_test/run.py
  • ```
  • However, running Python scripts in a subdirectory is not recommended because of problems with imports. That is — where would I put `pytest` fixtures and how would the `run` scripts access them? Not sure there is a good solution for that.
  • Could I use `pytest` to run my system tests? I imagine I'd need to change my command lines to something like this:
  • ```
  • python -m pytest -k speed_test_1
  • python -m pytest -k speed_test_2_this
  • python -m pytest -k speed_test_2_that
  • python -m pytest -k quality_test
  • ```
  • which looks ugly (e.g. there is no tab-completion for test names). And in addition, does pytest really support tests which have output other than pass/fail? I imagine there is something equally ugly I need to do to access my generated reports.
  • Is there a way I could use `pytest` or just any Python code to write system tests which could be invoked manually using shell-like syntax?
#1: Initial revision by user avatar anatolyg‭ · 2025-10-29T15:18:27Z (11 months ago)
How to use Python/pytest to organize unit and system tests?
I have a big system which I want to test using Python scripts: using `pytest` or any other infrastructure.

Some of my tests are of the "pass/fail" type; `pytest` has great support for these, like collecting, executing, summarizing, etc. Let's call them unit tests.

However, I have different tests, which produce some data about the system, like speed, quality, etc. I want to run these tests manually and examine the results (which are in csv or HTML format). Let's call them system tests.

Currently, I use shell-scripts for them. That means that any common part between these and unit tests has two versions: one written in shell language and another in Python.

How could I organize all my tests using Python?

I run my shell-scripts like this:

```
test/speed_test_1/run.sh
test/speed_test_2/run.sh
test/quality_test/run.sh
```

Naively, I'd like to rewrite them in Python and run like this:

```
test/speed_test_1/run.py
test/speed_test_2/run_this.py
test/speed_test_2/run_that.py
test/quality_test/run.py
```

However, running Python scripts in a subdirectory is not recommended because of problems with imports. That is — where would I put `pytest` fixtures and how would the `run` scripts access them? Not sure there is a good solution for that.

Could I use `pytest` to run my system tests? I imagine I'd need to change my command lines to something like this:

```
python -m pytest -k speed_test_1
python -m pytest -k speed_test_2_this
python -m pytest -k speed_test_2_that
python -m pytest -k quality_test
```

which looks ugly (e.g. there is no tab-completion for test names). And in addition, does pytest really support tests which have output other than pass/fail? I imagine there is something equally ugly I need to do to access my generated reports.

Is there a way I could use `pytest` or just any Python code to write system tests which could be invoked manually using shell-like syntax?