Python Book
🇺🇦 Stand with Ukraine🎓Training Suite
  • Book overview
  • Notes about this book
  • 1. Introduction to Python
    • What is Python
    • Basic syntax
    • Objects in Python
    • Python overview
    • Installation, IDEs etc.
    • ipython
    • Sources for self-learning
  • 2. Strings and numbers
    • Getting help
    • Introspection
    • Basic types
    • None object
    • Numbers
    • Strings
    • Unicode
    • String Formatting
    • Regular expressions
    • Sources for self-learning
  • 3. Containers
    • Data Structures
    • Lists
    • Tuples
    • Dictionaries
    • Sets
    • Conditions
    • Loops
    • Additional modules
    • Sources for self-learning
  • 4. Functions
    • Functions
    • Scopes of visibility
    • Generators
    • Lambdas
    • Type hints
    • Function internals
    • Sources for self-learning
  • 5. Functional Programming
    • Builtins
    • Iterable
    • Iterator
    • Functional Programming
    • Functools
    • Comprehensions
    • Additional modules
    • Sources for self-learning
  • 6. Code Styling
    • Zen of Python
    • Lint
    • PEP 8
    • Modules
    • Packages
    • Sources for self-learning
  • 7. OOP
    • OOP Basics
    • Code design principles
    • Classes
    • Method Resolution Order
    • Magic attributes and methods
    • Super
    • Sources for self-learning
  • 8. Decorators, Exceptions
    • Decorators
    • Exceptions
    • Sources for self-learning
  • 9. Testing
    • Basic Terminology
    • Testing theory
    • Dev unit testing vs QA automated testing
    • Best Practices
    • Doctest
    • Unittest
    • Test Runners
    • Pytest
    • Nose
    • Continuous Integration
  • 10. System Libs
    • Working with files
    • System libraries
    • Subprocess
    • Additional CLI libraries
Powered by GitBook
On this page

Was this helpful?

Edit on Git
  1. 9. Testing

Nose

Nose is handy to run all tests in a directory

pip install nose

$ nosetests

This command - nosetests - will automatically look for any modules (and packages) with tests (there are unittest or nose tests in modules in working directory and sub-directories if the names of those packages match "test" subword (-m option, NOSE_TESTMATCH).

Useful options:

  • Current directory is used as default working directory. It is possible to specify needed one (or several) via -w option:

nosetests -w parsing/ -w export/csv/tests/

Nose by default will look in current dir (or in -w specified) and will try to find files/dirs/tests that are matched by (-m argument).

  • Specifying a list of tests to run. nose allows specifying a set of tests on the command line. Only tests that are both discovered and in this set of tests will be run. For example:

nosetests -w parsing tests/test_csv.py:test_bigdata

only runs the function test_bigdata found in parsing/tests/test_csv.py.

  • Not capturing stdout via -s option. By default, nose captures all output and only presents stdout from tests that fail. So print() calls won't show anything. By specifying -s, this can be turned off for debugging purposes.

Other options:

  • -v - Verbose mode

  • -m - regex (NOSE_TESTMATCH) with files/dirs/tests to considered as tests

    • (default=(?:^|[\b_\.\-])[Tt]est)

    • better not change

  • -I - regex what files to ignore (--ignore-files=REGEX)

  • -i - regex with files/dirs/tests to be included

    • add something that is not covered by default -m

  • -e - regex with files/dirs/tests to be excluded

    • if we don't want to test specific files/cases

  • --processes - Parallel execution by nosetests (number of cores = processes):

nosetests --processes=4 tests.py

This is useful when testing UI with Selenium - but using number of parallel processes bigger than number of CPU cores is bad for performance.

PreviousPytestNextContinuous Integration

Last updated 2 years ago

Was this helpful?