question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Specify conftest / setup file in the ini file

See original GitHub issue

Description

Apparently my codebase uses this project so I’m just stumbling upon this, so forgive my ignorance if this exists or handled in another way

I’ve been trying to understand how the whole conftest.py system works cause I have two issues

  1. Specific file testing doesn’t use conftest.py i.e. tests don’t work if you want to run them individually
  2. Can’t specify a conftest depending on the testing style (we use unit + integration for example)

To elaborate on 1:

pytest -s -c=./config/python/pytest_unit.ini path/to/tests/file_test.py

if I put a conftest anywhere (path/*, or path/to/tests/*) it is not detected, but running without a path does detect it

To elaborate on 2:

I might want to disable internet access or setup mocks depending on the type of test I want to run (we use different ini files and suffix based file detection) but I don’t see the option in: https://docs.pytest.org/en/latest/reference.html#ini-options-ref (there is a useFixture but that doesn’t seem to solve my problem)

example unit.ini:

[pytest]
testpaths=path
python_files = *_test.py
addopts = --tb=native --disable-pytest-warnings
# Add this:
setup_file=path/setup_pytest.py

Extra

I’m getting ahead of myself but if this is something to add then pls comment with the places of which files to change (i.e. where the definitions are and where the code should go) if someone wants to write a PR so that they’re not daunted by the new codebase

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:24 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
jxramoscommented, Dec 16, 2020

@Azee77 the code changes needed should be fairly minimal, rename a file to something other than conftest.py so it is not included according to the conftest discovery rules, and then make that new name visible by including it in the root conftest.py file via the pytest_plugins = [...] mechanism. You still need to be sure your rootdir is set properly for that plugin to be visible from where you’re invoking, which hopefully was the repo1 level.

You might get some insight working through this set of pytest examples I wrote up recently https://github.com/jxramos/pytest_behavior

1reaction
nicoddemuscommented, Dec 4, 2019

Closing this because it hasn’t been answered in several months open

Thanks for the issue grooming btw Zac, appreciate it! Closing old issues without resolution sometimes is the ping needed to bring an issue back to attention. 😁

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pytest: Define custom path for tests collection - Stack Overflow
You need to explicitly specify the location of ini file. You can use -c argument to specify the location of your ini file....
Read more >
Understanding pytest Configuration Files - Python Testing with ...
pytest.ini · conftest.py: This is a local plugin to allow hook functions and fixtures for the directory where the conftest.py file exists and...
Read more >
Basic patterns and examples — pytest documentation
Here is a conftest.py file adding a --runslow command line option to control skipping of pytest.mark.slow marked tests: # content of conftest.py import ......
Read more >
Pytest - ini file - YouTube
Let's take a look at how you can utilize the ini file of pytest to customize our testing startegies.
Read more >
pytest Documentation
pytest -h | --help # show help on command line and config file options ... To set a breakpoint in your code use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found