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

Check if tests are coupled #1938

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8020173
Check if tests are coupled
IndrajeetPatil Mar 26, 2023
9e0b705
Merge branch 'main' into check-random-order
MichaelChirico Apr 9, 2023
d01a9e3
select a different seed each time
IndrajeetPatil Apr 15, 2023
c26668d
show the exact errors
IndrajeetPatil Apr 15, 2023
d462116
extract code to a script
IndrajeetPatil Apr 20, 2023
be21496
Merge branch 'main' into check-random-order
IndrajeetPatil Apr 20, 2023
b084cac
Update check-random-test-order.yaml
IndrajeetPatil Apr 20, 2023
72a5596
Merge branch 'main' into check-random-order
AshesITR Aug 13, 2023
f09b243
Merge branch 'main' into check-random-order
IndrajeetPatil Sep 8, 2023
397c072
Merge branch 'main' into check-random-order
IndrajeetPatil Sep 19, 2023
f6e3b2f
run on release version
IndrajeetPatil Sep 19, 2023
93d504f
Merge branch 'main' into check-random-order
IndrajeetPatil Nov 3, 2023
84fe347
Merge branch 'main' into check-random-order
IndrajeetPatil Dec 2, 2023
77270a2
Merge branch 'main' into check-random-order
IndrajeetPatil Mar 30, 2024
a90db51
Merge branch 'main' into check-random-order
IndrajeetPatil Apr 21, 2024
8d4629a
Merge branch 'main' into check-random-order
IndrajeetPatil May 6, 2024
b4dbcb2
Merge branch 'main' into check-random-order
IndrajeetPatil May 11, 2024
8099d9e
Merge branch 'main' into check-random-order
IndrajeetPatil Jun 12, 2024
49cd1c4
Merge branch 'main' into check-random-order
IndrajeetPatil Jun 17, 2024
5efb535
Merge branch 'main' into check-random-order
IndrajeetPatil Sep 7, 2024
e8b84ff
Merge branch 'main' into check-random-order
IndrajeetPatil Feb 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .dev/run-test-files-in-random-order.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
library(cli)
library(glue)
withr::local_envvar(TESTTHAT_PARALLEL = "FALSE")
pkgload::load_all(".")

test_script_paths <- testthat::find_test_scripts("tests/testthat")
seed <- sample.int(1e6, 1L)
cli_inform("Chosen seed for the current test run: {seed}")
set.seed(seed)
randomized_test_script_paths <- sample(test_script_paths)

any_test_failures <- FALSE
any_test_errors <- FALSE

test_path <- function(path) {
report <- as.data.frame(testthat::test_file(path, reporter = "silent"))
has_test_failures <- any(report$failed == 1L)
has_test_errors <- any(report$error == 1L)
if (has_test_failures) {
cli_alert_danger(glue("Tests in `{path}` are failing."))
any_test_failures <<- TRUE
failed_tests <- tibble::as_tibble(subset(report, failed == 1L)[, c("test", "result")])
print(glue::glue_data(failed_tests, "Test `{test}` is failing:\n{purrr::pluck(result, 1L, 1L)}"))
}
if (has_test_errors) {
cli_alert_danger(glue("There was error while running tests in `{path}`."))
any_test_errors <<- TRUE
errored_tests <- tibble::as_tibble(subset(report, error == 1L)[, c("test", "result")])
print(glue::glue_data(errored_tests, "Test `{test}` has error:\n{purrr::pluck(result, 1L, 1L)}"))
}
if (!has_test_failures && !has_test_errors) {
cli_alert_success(glue("All tests passing in `{path}`."))
}
}

cli_rule()
cli_inform("Running tests in random order:")
cli_rule()

purrr::walk(randomized_test_script_paths, test_path)

cli_rule()
if (any_test_failures) {
cli_abort("Tests in some files are failing.")
}

if (any_test_errors) {
cli_abort("There was error while running tests in some files.")
}

if (!any_test_failures && !any_test_errors) {
cli_alert_success("Tests from all files are passing!")
}
cli_rule()
35 changes: 35 additions & 0 deletions .github/workflows/check-random-test-order.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Run tests in random order
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: check-random-test-order

jobs:
check-random-test-order:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2
with:
r-version: "release"
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
pak-version: devel
extra-packages: |
local::.

- name: Run Tests in Random Order
run: |
options(crayon.enabled = TRUE)
callr::rscript(".dev/run-test-files-in-random-order.R")

shell: Rscript {0}
Loading