Moshe S.
Moshe S.

Reputation: 3044

How can I convert a .py script into a formal test?

I am new to python and my goal is to construct an automation environment in my department. I am a QA Engineer and I would like to automate my functional Tests. I chose python for this purpose because i found out, during a research that I made, that python has all the modules that I need in order to fully automate my Functional Tests:

  1. Selenium Webdriver
  2. Control test/measurement devices with SCPI
  3. Telnet or SSH my devices
  4. SNMP

I have started my work by writing short verification tests. I wanted to see that i am able to automate my functional tests according to the list above.

I have some .py files that are actually tests actually tests and I would like to know:

  1. Can I convert them into pytest ?
  2. If I manage to run my automated functions (test) by running .py scripts why should I work with pytest ?

Upvotes: 1

Views: 909

Answers (1)

Frank T
Frank T

Reputation: 9046

  1. The short answer is "yes", it's easy to use pytests for existing tests. I'll explain below.
  2. pytest makes it easy to collect your tests, run your tests, and provide output about your test run.

Fundamentally a test is some executable code that verifies some system behavior and raises an assertion exception when that behavior doesn't match expectations.

pytest can help you with your test suite:

  • It provides a "test collector", a utility to find code that looks like tests, and to have you specify which tests you want to run, etc.
  • It provides a "test runner", an execution framework to run your tests, gather results, and report on those results.
  • It also provides a powerful concept of "fixtures", which allow you to decouple test setup from the behavior being verified.

To answer your first question more specifically: either name your test files, functions, and classes according to the defaults (here's pytest's documentation on how it collects tests by default), or you can change the defaults. By default, basically have your test directories start with test_, classes start with Test, and functions start with test_. It's heavily customizable too.

Upvotes: 1

Related Questions