Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change in data source passed with pytest.mark.parametrize does not cause test rerun #115

Closed
skyegecko opened this issue Sep 24, 2018 · 4 comments

Comments

@skyegecko
Copy link

Our testsuite has a number of tests which are run with parametrized data. The data source in turn is a variable (usually a list of some kind) in another module. When the data is altered, testmon fails to rerun the affected test.

Simple dummy project example:

File test_list.py:

import pytest
import data

@pytest.mark.parametrize("testdata", data.listdata)
def test_list(testdata):
    assert testdata

File data.py:

listdata = [
    True,
    True,
    True,
]

In this example, appending an item to listdata will not result in test_list being selected in the next test run.

Python version: 3.4.5
Pytest version: 3.8.1 (source: pip)
pytest-testmon version: 0.9.13 (source: pip)

@skyegecko skyegecko changed the title Change in data source passed with pytest.mark.parametrize does not case test rerun Change in data source passed with pytest.mark.parametrize does not cause test rerun Sep 24, 2018
@tarpas
Copy link
Owner

tarpas commented Sep 24, 2018

Thanks for the clear bug report. At a first sight I think this is conceptual weakness of testmon and it might take longer to fix. I'll write more when I have more time.

@tarpas
Copy link
Owner

tarpas commented Oct 3, 2019

@dutchgecko unfortunately won't fix (in the near future). It would be possible to react to the change but that would eliminate most of the potential time savings that testmon is designed to achieve. The (data) library is imported (and the data is initialized) before any test is run. Usually that's true for all tests and all files under test. We ignore what is executed during the import(collection) phase and assume dependency on any file in your project which executes at least on line from the setup, call or teardown phase of a test.

There is probably a workaround where you could make pytest execute a function during the setup phase to get the parametrization data:
https://raphael.codes/blog/pytest-parametrize-with-indirect/

It seems quite verbose and I don't have experience with it.

@tarpas
Copy link
Owner

tarpas commented Oct 4, 2019

@dutchgecko or in a primitive, heavy handed but clearer way:

  • to data.py add:
def ping():
    return 0
  • and then call it from inside the test function: data.ping() The rest stays the same as in your original version

@tarpas
Copy link
Owner

tarpas commented Nov 9, 2023

This is a duplicate of #191 (which described the more general case)

@tarpas tarpas closed this as completed Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants