PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, September 14, 2022

[FIXED] How to run pytest from console menu?

 September 14, 2022     exec, pytest, python     No comments   

Issue

I have console-menu, like:

if n == 1:
    exec('pytest test_1.py' ) # example, it doesn't work
elif n == 2:
    exec('pytest test_2.py' ) # example, it doesn't work

and login.py:

from functools import partial
import pytest_bdd

scenario = partial(pytest_bdd.scenario, '..\\login.feature')

@Scenario('login 2')
def test_2():
    pass()

and I want to start pytest for special methods (test_2), when I use this menu. Now I runnig my pytest from PyCharm terminal or "run""debug".

How can I use exec() from python for call pytest?
Like:

exec('pytest -s login.test_2')

Is it possible? Or maybe it has another way?


Solution

I think you can call pytest using subprocess:

import subprocess
subprocess.run(["pytest", "-s", "login.test_2"])


Answered By - Daniel
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing