Background
I have am using pytest to test a web scraper that pushes the data to a database. The class only pulls the html and pushes the html to a database to be parsed later. Most of my tests use dummy data to represent the html.
Question
I want to do a test where a webpage from the website is scraped but I want the test to be automatically turned off unless specified. A similar scenario could be if you have an expensive or time consuming test that you do not want to always run.
Expected Solution
I am expecting some kind of marker that suppresses a test unless I give pytest to run all suppressed tests, but I do not see that in the documentation.
What I have done
- I am currently using the skip marker and comment it out.
Tried to use the skipif marker and and give arguments to python script using this command from command prompt
pytest test_file.py 1
and the following code below in the test file. The problem is that when I try to provide an argument to my test_file, pytest is expecting that to be another file name so I get an error "no tests run in 0.00 seconds, ERROR: file not found: 1"if len(sys.argv) == 1: RUN_ALL_TESTS = False else: RUN_ALL_TESTS = True ... # other tests ... @pytest.mark.skipif(RUN_ALL_TESTS) def test_scrape_website(): ...
I might be able to treat the test as a fixture and use
@pytest.fixture(autouse=False)
, not sure how to override the autouse variable thoughA similar solution was stated in How to skip a pytest using an external fixture? but this solutions seems more complicated than what I need.