最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Pytest: Rerun tests in the same session after changing environments? - Stack Overflow

programmeradmin2浏览0评论

I'm using pytest to run tests across three different environments, and using markers to control which test cases are being executed during a test run.

To optimize the process, I'm using a session-scoped fixture to handle the program's startup, which takes a few minutes. This ensures the program starts only once per test run.

Since I can switch environments freely once the program is running, I want to execute all tests in one environment, then switch to the next environment and rerun the same tests, all within the same pytest session.

Ideally, this would look like:

  1. Execute a test run, defining which test cases to run utilizing marks
  2. Program startup happens
  3. Run the selected test cases in environment 1
  4. All test cases finish running
  5. Switch to environment 2
  6. Re-run the selected test cases
  7. All test cases finish running
  8. Switch to environment 3
  9. ... and so on...
  10. Program teardown happens

Also, to avoid hardcoding, I need a way to configure the test run to execute in any number of environments without modifying the test code itself.

Is this possible within a single pytest session? What approaches or features could help me achieve this?

发布评论

评论列表(0)

  1. 暂无评论