1) First of all, you can declare those fixtures not only in conftest.py, but in every Python module you want. And you can import that module. Also you can use fixtures in the same way as you used setUp method:

@pytest.fixture(scope='class')
def input(request):
    request.cls.varA = 1
    request.cls.varB = 2
    request.cls.varC = 3
    request.cls.modified_varA = 2

@pytest.usefixtures('input')
class TestClass:
    def test_1(self):
        do_something_with_self.varA, self.varB

    def test_2(self):
        do_something_with_self_modified_varA, self.varC

or you can define separate variables in separate fixtures:

def fixture_a():
    return varA

def fixture_b():
    return varB

def fixture_c():
    return varC

def fixture_mod_A():
    return modified_varA

or make one fixture which returns all the variables (why not?) or even make indirect parametrized fixture which returns variables by your choice (quite confusing way):

@pytest.fixture()
def parametrized_input(request):
   vars = {'varA': 1, 'varB': 2, 'varC': 3}
   var_names = request.param
   return (vars[var_name] for var_name in var_names)

@pytest.mark.parametrize('parametrized_input', [('varA', 'varC')], indirect=True)
def test_1(parametrized_input)
   varA, varC = parametrized_input
   ...

Or even you can make fixture factory which will make fixtures for you on the fly. Sounds curiously when you have only 5 tests and 5 configurations of variables, but when you get hundreds of both, it can be useful.

3) Of course you can. But I recommend you not to import this file directly, but use command line option pointing what file to import. In this case you can choose another file with variables without changing your code.

4) I use classes in my tests because I migrated from nosetest. I didn't mention any problem with using classes in pytest.

5) In that case I propose you to do the following: fist make the function with desired actions:

def some_actions(a, b):
    # some actions here
    ...
    return c

then use it both in test and fixture:

def test():
    assert some_actions(1,2) == 10

@pytest.fixture()
def some_fixture():
     return some_actions(1,2)
Answer from Ilya Karpeev on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › software testing › difference-between-pytest-and-unittest
Pytest Vs Unittest - GeeksforGeeks
May 26, 2026 - Pytest is known for its simple syntax, flexibility, and powerful features. Unittest provides a structured, class-based testing approach and is included in Python’s standard library.
Discussions

python - unittest vs pytest - Stack Overflow
One comment though: I think instead ... @pytest.mark.usefixtures should be used. 2018-05-18T09:30:29.873Z+00:00 ... Save this answer. ... Show activity on this post. I think unittest is easier to read. For new testers, unittest is really easy. It is working out of the box. You depend on the Python implementation, ... More on stackoverflow.com
🌐 stackoverflow.com
PyTest or Unittest?
Pytest because I’ve never liked the xUnit style pattern of inheriting from a base class and implementing setup and tear down methods. Its fixtures concept is pretty cool—basically dependency injection for test objects. But it is possible to make things far more complex if you overuse them so I try not to create too many of them. Also, I tend to follow Luke Plant’s advice when it comes to building factories for test data . Lastly, tests aren’t just good for finding and preventing bugs. They should be seen as the most minimal thing possible to exercise your code. If it’s hard to write a test, then your design could probably use some more thought. More on reddit.com
🌐 r/django
17
11
January 7, 2025
Testing with pytest and unittest
Every Python project I create, I will use *pytest* extensively. Testing is fundamental for every project larger than 300 lines of code. If you give me a piece of code, I will give you the associated (pytest) unit tests. (credits: software/data engineer with 15 years of professional experience, and 38 years of programming experience) More on reddit.com
🌐 r/PythonLearning
9
8
July 19, 2025
What is the most common Unit Test method?
unittest.TestCase.assertEqual More on reddit.com
🌐 r/learnpython
11
6
September 4, 2025
🌐
JetBrains
jetbrains.com › guide › pytest › links › pytest-v-unittest
pytest vs Unittest, Which is Better? - JetBrains Guide
March 15, 2024 - Pytest offers advantages like automatic test discovery, skip/xfail tests, and powerful assertion introspection. It also supports parallel test execution and offers easy mocking and patching.
🌐
Trunk
trunk.io › home › learn › pytest vs unittest: a comparison
Pytest vs Unittest: A Comparison
October 22, 2024 - Compare Pytest vs Unittest: Discover why Pytest is favored for its simplicity, fixtures, and plugins, while Unittest remains a solid choice for structured, legacy testing.
Top answer
1 of 2
84

1) First of all, you can declare those fixtures not only in conftest.py, but in every Python module you want. And you can import that module. Also you can use fixtures in the same way as you used setUp method:

@pytest.fixture(scope='class')
def input(request):
    request.cls.varA = 1
    request.cls.varB = 2
    request.cls.varC = 3
    request.cls.modified_varA = 2

@pytest.usefixtures('input')
class TestClass:
    def test_1(self):
        do_something_with_self.varA, self.varB

    def test_2(self):
        do_something_with_self_modified_varA, self.varC

or you can define separate variables in separate fixtures:

def fixture_a():
    return varA

def fixture_b():
    return varB

def fixture_c():
    return varC

def fixture_mod_A():
    return modified_varA

or make one fixture which returns all the variables (why not?) or even make indirect parametrized fixture which returns variables by your choice (quite confusing way):

@pytest.fixture()
def parametrized_input(request):
   vars = {'varA': 1, 'varB': 2, 'varC': 3}
   var_names = request.param
   return (vars[var_name] for var_name in var_names)

@pytest.mark.parametrize('parametrized_input', [('varA', 'varC')], indirect=True)
def test_1(parametrized_input)
   varA, varC = parametrized_input
   ...

Or even you can make fixture factory which will make fixtures for you on the fly. Sounds curiously when you have only 5 tests and 5 configurations of variables, but when you get hundreds of both, it can be useful.

3) Of course you can. But I recommend you not to import this file directly, but use command line option pointing what file to import. In this case you can choose another file with variables without changing your code.

4) I use classes in my tests because I migrated from nosetest. I didn't mention any problem with using classes in pytest.

5) In that case I propose you to do the following: fist make the function with desired actions:

def some_actions(a, b):
    # some actions here
    ...
    return c

then use it both in test and fixture:

def test():
    assert some_actions(1,2) == 10

@pytest.fixture()
def some_fixture():
     return some_actions(1,2)
2 of 2
35

I think unittest is easier to read. For new testers, unittest is really easy. It is working out of the box. You depend on the Python implementation, but they will not change the interface coming years.

I like to organize my tests in such a way that I have maximum 1 test per file. In that case I don't depend on classes... but I import classes from every test to do stuff.

Some websites complain about colours in unittest is not possible. I think that is a joke, since my unittests create JUNIT output reports for Jenkins and others. There are great tools (even 1 file) to convert JUNIT to a website, that's not the responsibility of a test tool.

Also, some people complain you need a lot of code to start a unittest. I disagree, it takes 4 lines of code to create a unittest! But Pytest needs to know all the difficult annotations, which are not normal for a simple Python developer.

An important reasons also is that unittest will remain free. However, if you want to use pytest for some reason (bitbucket etc), there are tools to convert your tests and make the code less readable.

Have fun!

🌐
Medium
laerciosantanna.medium.com › pytest-vs-unittest-navigating-pythons-testing-terrain-2569912a0286
PyTest vs. unittest: A Comparative Guide for Python Testing | by Laércio de Sant' Anna Filho | Medium
February 10, 2024 - Both PyTest and unittest provide valuable tools for testing Python applications. Ultimately, the ideal choice depends on the nature of your project, team preferences, and individual testing styles. The strengths of PyTest have led to its widespread adoption, but unittest remains a viable option, especially in environments reliant on the standard library.
Find elsewhere
🌐
BrowserStack
browserstack.com › home › guide › pytest vs. unittest: which is the better choice for your test automation cycle
pytest vs Unitest: Exploring Test Suites For Enterprises in 2026 | BrowserStack
August 20, 2026 - While unittest locks developers into rigid class lifecycles, pytest introduces a modular dependency injection model. pytest has become a default choice for testers who wish to optimise their scripting process and auto-assert commands without ...
🌐
Early
startearly.ai › home › blog › pytest vs unittest: which is right for you?
Pytest vs Unittest: Which is right for you? | Early
June 22, 2025 - Unittest integrates well with Python’s standard tools, but is best suited for legacy or highly structured codebases where consistency and traceability are more important than speed and flexibility. Pytest is a lightweight, function-based testing framework that prioritizes simplicity and flexibility.
🌐
Qaskills
qaskills.sh › home › blog › python unittest vs pytest: which to choose in 2026?
Python unittest vs pytest: Which to Choose in 2026? | QASkills.sh
March 24, 2026 - For the vast majority of Python projects in 2026, pytest is the better choice. Its lower boilerplate, superior fixtures, plugin ecosystem, and excellent assertion introspection make it more productive.
🌐
Quora
quora.com › Which-Python-unit-test-framework-should-I-use
Which Python unit test framework should I use? - Quora
Answer: Hello, According to my experience, Initially I started with unit test as its a default framework of python and then later i moved to py.test which gives better output in details and also we can integrate many plugins
🌐
Continuously Merging
articles.mergify.com › unittest-vs-pytest
Unittest vs Pytest: Which Python Testing Framework is Best?
May 20, 2025 - Its simpler syntax, powerful fixture system, and extensive plugin ecosystem have contributed to its rise as the de facto standard for Python testing, surpassing unittest in popularity. pytest's key strength lies in its ability to streamline the testing process.
🌐
Katalon
katalon.com › resources-center › blog › pytest-vs-unittest-comparison
Pytest vs Unittest: Syntax, Fixtures, and Speed
1 week ago - Selecting the optimal Python testing framework depends on your project's unique demands; Pytest offers a modern, flexible, and feature-rich approach ideal for efficiency and scalability, while Unittest provides a stable, built-in, class-based structure suitable for established projects or those needing strict organizational control.
🌐
Exercism
exercism.org › tracks › python › concepts › basics
Basics in Python on Exercism
Docstrings can also function as lightweight unit tests, which can be read and run by PyTest, or by importing the doctest module.
🌐
Built In
builtin.com › data-science › pytest-vs-unittest
Pytest vs. Unittest: A Comparison and How-to Guide | Built In
Pytest: pytest is a Python testing framework that requires installation and emphasizes simplicity, scalability and ease of use. It also offers extensive plugin support. Unittest: unittest is a testing framework that’s part of Python’s standard library.
🌐
Roadmap
roadmap.sh › python
Learn to become a modern Python developer
May 14, 2025 - To become a Python developer, the first step is learning the basics of Python, including data types and null values, functions, and object-oriented programming (you can get away without learning OOP as well since Python allows for a hybrid programming model).
🌐
daily.dev
daily.dev › home › jetbrains › pytest vs. unittest: which is better?
Pytest vs. Unittest: Which Is Better? | daily.dev
March 15, 2026 - This post compares pytest and unittest, two popular Python testing frameworks, and discusses their features, advantages, and disadvantages. It also explains...
🌐
DEV Community
dev.to › nkpydev › python-testing-unit-tests-pytest-and-best-practices-45gl
Python Testing – Unit Tests, Pytest, and Best Practices - DEV Community
March 8, 2025 - ✅ Unit tests ensure correctness and prevent regressions. ✅ unittest is built-in but pytest makes testing easier. ✅ Fixtures and parameterized tests improve test coverage. ✅ Mocking allows testing code with external dependencies.
🌐
Libhunt
python.libhunt.com › compare-unittest-vs-pytest
unittest vs pytest | LibHunt - Awesome Python
Compare unittest and pytest's popularity and activity. Categories: Testing and Testing Frameworks.