Skip to main content
ubuntuask.com

Back to all posts

How to Run Only Unmarked Tests In Pytest?

Published on
4 min read
How to Run Only Unmarked Tests In Pytest? image

Best Python Testing Tools to Buy in October 2025

1 Learning Selenium Testing Tools with Python

Learning Selenium Testing Tools with Python

BUY & SAVE
$84.00
Learning Selenium Testing Tools with Python
2 Test-Driven Development with Python: Obey the Testing Goat: Using Django, Selenium, and JavaScript

Test-Driven Development with Python: Obey the Testing Goat: Using Django, Selenium, and JavaScript

BUY & SAVE
$38.26 $69.99
Save 45%
Test-Driven Development with Python: Obey the Testing Goat: Using Django, Selenium, and JavaScript
3 Crafting Test-Driven Software with Python: Write test suites that scale with your applications' needs and complexity using Python and PyTest

Crafting Test-Driven Software with Python: Write test suites that scale with your applications' needs and complexity using Python and PyTest

BUY & SAVE
$37.56 $48.99
Save 23%
Crafting Test-Driven Software with Python: Write test suites that scale with your applications' needs and complexity using Python and PyTest
4 Security Automation with Python: Practical Python solutions for automating and scaling security operations

Security Automation with Python: Practical Python solutions for automating and scaling security operations

BUY & SAVE
$28.57 $49.99
Save 43%
Security Automation with Python: Practical Python solutions for automating and scaling security operations
5 Robust Python: Write Clean and Maintainable Code

Robust Python: Write Clean and Maintainable Code

BUY & SAVE
$26.58 $55.99
Save 53%
Robust Python: Write Clean and Maintainable Code
6 Hypermodern Python Tooling: Building Reliable Workflows for an Evolving Python Ecosystem

Hypermodern Python Tooling: Building Reliable Workflows for an Evolving Python Ecosystem

BUY & SAVE
$37.53 $65.99
Save 43%
Hypermodern Python Tooling: Building Reliable Workflows for an Evolving Python Ecosystem
7 Learning Test-Driven Development: A Polyglot Guide to Writing Uncluttered Code

Learning Test-Driven Development: A Polyglot Guide to Writing Uncluttered Code

BUY & SAVE
$36.49 $65.99
Save 45%
Learning Test-Driven Development: A Polyglot Guide to Writing Uncluttered Code
8 The 7-Day Python Crash Course For Absolute Beginners: Learn to Build Real Things, Automate Repetitive Work, and Think Like a Coder — With 100+ Scripts, Functions, Exercises, and Projects

The 7-Day Python Crash Course For Absolute Beginners: Learn to Build Real Things, Automate Repetitive Work, and Think Like a Coder — With 100+ Scripts, Functions, Exercises, and Projects

BUY & SAVE
$22.90
The 7-Day Python Crash Course For Absolute Beginners: Learn to Build Real Things, Automate Repetitive Work, and Think Like a Coder — With 100+ Scripts, Functions, Exercises, and Projects
9 Python Testing with pytest: Simple, Rapid, Effective, and Scalable

Python Testing with pytest: Simple, Rapid, Effective, and Scalable

BUY & SAVE
$37.52
Python Testing with pytest: Simple, Rapid, Effective, and Scalable
+
ONE MORE?

In pytest, you can run only unmarked tests by using the "-m" option along with the "not" keyword. This allows you to select tests based on markers that have not been applied to them. For example, you can run only unmarked tests by using the command "pytest -m 'not marked_test'". This will execute all tests that do not have the "marked_test" marker assigned to them. This can be useful when you want to run a subset of tests that have not been labeled with specific markers, such as tests that have not been marked for performance testing or integration testing.

How to run all unmarked tests in a pytest suite?

To run all unmarked tests in a pytest suite, you can use the -k option to specify a keyword pattern that matches the unmarked tests. Here's how you can do it:

  1. Open a terminal or command prompt.
  2. Navigate to the directory where your pytest suite is located.
  3. Run the following command to run all unmarked tests:

pytest -k "not mark"

This command will run all tests that are not marked with any markers. You can also customize the keyword pattern to match specific unmarked tests by modifying the -k option accordingly.

  1. Press Enter to execute the command and run the unmarked tests in your pytest suite.

By using the -k option with the appropriate keyword pattern, you can easily run all unmarked tests in a pytest suite.

How to run only unmarked tests in pytest?

To run only unmarked tests in pytest, you can use the -m flag with the not keyword to select tests that do not have the specific marker. Here's how you can do it:

  1. Run the following command in your terminal:

pytest -m "not marker_name"

Replace marker_name with the actual marker name that you want to exclude.

For example, if you have tests marked with the marker slow, you can exclude them by running:

pytest -m "not slow"

This command will run all the tests that are not marked with the specified marker.

  1. Another option is to use custom expressions for selecting tests based on markers. You can define a custom marker in pytest.ini file and use it to filter the test cases. Here's an example:

In pytest.ini:

markers = mymarker: select tests that are not marked with mymarker

And then in your command line, run:

pytest -m "not mymarker"

This will run only the tests that are not marked with mymarker.

By using the -m flag with the not keyword or custom expressions in pytest.ini, you can easily run only unmarked tests in pytest.

What is the criteria for selecting tests to run in pytest?

There are a few key criteria to consider when selecting tests to run in pytest:

  1. Importance: Prioritize tests based on the criticality of the functionality being tested. Tests for crucial features should be run more frequently than tests for less critical features.
  2. Frequency of failure: Tests that have a history of failing frequently should be included in the test suite to ensure that any regressions are caught early.
  3. Coverage: Make sure that the test suite covers a wide range of functionality and edge cases to ensure comprehensive testing of the application.
  4. Performance impact: Consider the performance impact of running certain tests and prioritize tests that have a significant impact on the overall performance of the application.
  5. Dependencies: Ensure that tests are run in the correct order, taking into account any dependencies between different test cases or modules.
  6. Regression testing: Include tests that cover any recent changes or bug fixes to ensure that the application continues to function as expected after updates.

By considering these criteria, you can create a well-rounded and effective test suite in pytest to ensure the quality and stability of your application.